In JavaScript logic operations, 0, "", null, False, undefined, Nan will be sentenced to false, the others are true;
In JavaScript, the first JS will be && and | | The values on both sides are converted to a Boolean type, and then the value,&& operation returns True if the following value is taken, if | | Returns true to take the preceding value,
Conversion rules:
object is true;
Non 0 digit is true;
The non-empty string is true;
others are false;
1, as long as "| |" False before, regardless of ' | | ' Followed by true or FALSE, the result returns "| |" The value that follows.
2, as long as "| |" Preceded by true, regardless of "| |" Followed by true or FALSE, the result returns "| |" The preceding value.
3, as long as "&&" is false, whether "&&" followed by true or false, the result will be "&&" the preceding value;
4, as long as "&&" is true, whether "&&" followed by true or false, the result will be returned to "&&" the value after;
logical operators, "| |" and "&&" are to follow the short-circuit principle, as long as the symbol before the true and false, can determine the return value.
It should be stated that the priority of "&&" is higher than "| |" Of
// if Foo exists, the value is not changed, otherwise the value of bar is assigned to Foo
Equals
if (! ODI) { ODI= attr;}
Why if (!odi), why not write directly if (ODI)?
In fact, this is a more rigorous way of writing:! The function is to convert a variable of another type to the bool type.
The difference between the selected typeof 5 and typeof!5 can be tested, and the return is number and Boolean;
JS in About | | and && as well! The understanding