The logical operators in JS are not different from other languages when dealing with Boolean judgments, but when dealing with objects, it is necessary to comb the memory.
Logical NON (!)
Returns False if an operand is an object;
Returns False if an operand is an empty string;
Returns False if an operand is a non-empty string;
Returns true if an operand is a numeric value of 0;
Returns False if an operand is an arbitrary non-0 character;
Returns true if an operand is null;
Returns true if an operand is Nan;
Returns True if an operand is undefined;
PS: In fact, it is easy to see the value of its logical judgment.
Logic and (&&)
(1) For Boolean values, logic and is very simple, as long as there is a false, return false;
(2) For cases where the Boolean value is not true:
Returns a second number if the first operand is an object
If the second operand is an object, the object is returned only if the value of the first operand evaluates to true;
If the first two operands are objects, the second operand is returned
Returns null if one of the operands is null
If one of the operands is Nan, the first Nan is returned
Returns undefined if the first operand is undefined
PS: In fact, think about it, the logical operator operators follow the order from left to right, the logic and Operators (&&) first to determine the first number, if the first number of logical judgment is true, you also need to determine the second number, the result of the output of the second operand; If the first number is false, then the second number is not considered, directly output the logical judgment result of the first number, which is the same as other language principles.
Logic or (| |)
(1) For Boolean values, logical or very simple, as long as there is a true, return true;
(2) For cases where the Boolean value is not true:
If the first operand is an object, the first operand is returned
Returns the second operand if the evaluation result of the first operand is false
If two operands are objects, the first operand is returned
Returns NULL if two operands are null
If two operands are Nan, a nan is returned
If two operands are undefined, the undefined is returned
PS: Principle with logic (&&), logic or (| |) The judgment is that if the logic of the first operand evaluates to true, the first operand is output, the second operand is not considered, and the logic of the second operand is determined if the logic of the first operand is false.
The "JS" logical operator is not! With && or | |