- ++ Increment
- -- Decrement
- = = = Exactly equal to (both value and type)
- || Logical Or
- x = y++ => {x = y; y = y + 1;}
- x = ++ y => {y = y + 1; x = y;}
- "5" === 5 => returns false, as type is not same.
- The Logical OR operator (||) will short-circuit and return the first truthy value.
There is a common usage for Logical Or operator, which is to setting default values to function arguments, e.g.
function doSomething(e) {
e = e || window.event
alert(e.type);
}
=>
function doSomething(e) {
if (!e) e = window.event;
alert(e.type);
}
The Logical OR || operator will return its second operand if the first one is falsy
Falsy values are: 0, null, undefined, an empty string, NaN, and false
No comments:
Post a Comment