In JavaScript, falsy values are values that are considered false
when evaluated in a Boolean context (e.g., inside an if
statement). Here is a list of all falsy values:
false
– Boolean false
0
– The number zero0
– Negative zero0n
– B igInt zero""
– An empty stringnull
– The absence of any valueundefined
– A variable that has not been assigned a valueNaN
– "Not a Number", a value representing invalid number resultsIn JavaScript, truthy values are all values that are not falsy. These values are considered true
when evaluated in a Boolean context. Here is a list of truthy values:
true
– Boolean true
"hello"
, " "
).0
and 0
(e.g., 1
, 5
, 3.14
).0n
(e.g., 1n
, 1000n
).{}
, []
, function() {}
).[]
, [1, 2, 3]
).new Date()
– A Date object (e.g., new Date()
).