When learning the logical expressions, I learned some points that I didn't understand before and recorded them.
operator "&&"
The "&&" operator can be understood from three different levels:
First layer: When the operands are all Booleans, "&&" performs a Boolean and (and) operation on two values, which returns true only if the first operand and the second operand are true.
The second layer: && can perform Boolean and (and) operations on Truth and value (False,null,undified,0,-0,nan and "").
The third layer: the operator first calculates the value of the left operand, and if the result is a false value, then "&&" simply returns the value of the left operand, and if the left operand of the expression is true, the "&&" operator returns the value of the right operand and evaluates it as the entire expression.
Such as:
var person={name:"wxt"}; var nperson=null;p erson&&person.name // return Person.name nperson&&nperson.name // return Nperson
operator ' | | '
Same "| |" The value of the first operand is computed first, if the result is true, then the value of the second operand is returned, and the result of the expression evaluates.
JavaScript logical expression ' && ' and ' | | '