JavaScript Boolean Type
Truthy
We did say that Boolean only had two possible values: true or
false. In JavaScript, we also have something called truthy and
falsy values.
Truthy values are treated as true when used in a Boolean context
(conditionals, etc).
Falsy values are treated as false when used in a Boolean context
(conditionals, etc).
The general rule is that all JavaScript values are considered true
unless they are one of the following values:
false: False is falsy; no surprises there.0,-0,0n: The number zero is considered falsy."": The empty string is falsy.null: Abscence of any object value is falsy.undefined: Unassigned value is falsy.NaN: Not a Number is falsy (result from possible invalid number operations).
// all falseconst a = Boolean(false)const b = Boolean(0)const c = Boolean(-0)const d = Boolean(0n)const e = Boolean("")const f = Boolean(null)const g = Boolean(undefined)const h = Boolean(NaN)