In JavaScript, "falsey" values are those that evaluate to false in expressions such as if(value), value ? and !value.
"Falsey" simply means that JavaScript's ToBoolean function returns false for that value. ToBoolean underlies expressions like !value, value ? ... : ..., and if (value).
According to the official ECMAScript specification, the following rules apply to ToBoolean:
Argument type | Result |
---|---|
Undefined | Return false |
Null | Return false |
Boolean | Return argument |
Number | If argument is 0, -0, or NaN, return false; otherwise, return true |
String | If argument is an empty string (length 0), return false; otherwise, return true |
BigInt | If argument is 0n, return false; otherwise, return true |
Symbol | Return true |
Object | Return true |
The above is the detailed content of What are the Falsey Values in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!