java-script:falsy-truthy-values
Table of Contents
Java Script Falsy and Truthy Values
Falsy values
A falsy value is a value considered false if it's encountered in a boolean context.
These are the falsy values:
- false: The keyword false itself is obviously considered falsy.
- 0, -0, 0n, -0n: The number zero (including its negative counterpart and big int) is considered falsy.
- “”, '' and `` (empty strings): An empty string is considered falsy.
- null: The null keyword is considered falsy.
- undefined: The undefined keyword is also falsy.
- NaN: “Not a Number” is considered falsy.
Truthy values
Everything that is not a falsy value is a truthy value.
This includes:
- '0'
- 'false'
- []
- {}
- function () {}
java-script/falsy-truthy-values.txt · Last modified: 2023/08/09 20:47 by odefta