+ 8
The AND Operator (JS Demystified)
Classical Meaning: alert(true && true) // true alert(true && false) // false alert(false && true) // false alert(false && false) // false JS Quirks: 1. Reads from Left to Right 2. Convert Operand to Boolean (any value type) 3. Returns the First Falsy (original value) 4. Returns last value if all operands are truthy. Examples: alert(1 && null) // null alert(2 && alert(1) && 3) // undefined alert(1 && 2 && 3) // 3
4 Answers
+ 5
@Marat the OR operator returns the first truthy value. Hence the following:
alert(1 || NaN) // 1
alert(1 || null) // 1
alert(1 || undefined) //1