The first statement will return always true except the case when a is NaN
Why
NaN == NaNreturns false ?
Because the JS spec says so:
- If Type(x) is Number, then
- If x is NaN, return false.
- If y is NaN, return false.
The second statement will return true only if a is not a falsy variable.
When I say falsy i mean undefined, null , 0, ”. A falsy value is a value that translates to false when evaluated in a Boolean context.
In JavaScript, a truthy value is a value that is considered true when evaluated in a Boolean context. All values are truthy unless they are defined as falsy (i.e., except for false, 0, “”, null, undefined, and NaN).
A falsy value is a value that translates to false when evaluated in a Boolean context.
1
solved Difference between a==a?a:b and a?a:b