A
A
Aljo2021-07-07 19:55:10
JavaScript
Aljo, 2021-07-07 19:55:10

Can you explain what this line of code means?

The site has an ajax form, I need to put recaptcha3.
I understand that it seems that in this line there is a check for the completeness of the form fields, but I have a few questions:

return $(this).find('input[name="DATA[NAME]"]').val().length < 2 ? (alert("Введите имя"), !1) : 0 == IsEmail(t) ? (alert("Введите корректный email"), !1) : ($.ajax({...тут отправка формы

1. I have already read about the question mark, a la ternary operator, and basically understood how it works, but what does == mean here ? I thought it was a comparison operator or does it have other functions? It just seems to me that he compares name with email here, or am I misunderstanding?
2. What does !1 mean inside alert?
2. How to write another condition here if (captcha.length)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Gololobov, 2021-07-07
@aljo222

Break code into if-else

if ($(this).find('input[name="DATA[NAME]"]').val().length < 2 ) {
     return (alert("Введите имя"), !1)
} else if (0 == IsEmail(t)) {
  return (alert("Введите корректный email"), !1)
} else {
   return ($.ajax({...тут отправка формы})
}

2. !1 -> false
3. After you decompose everything into if-else, you can put captcha.length where it is convenient for you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question