Returns false
if its single operand can be converted to true
; otherwise, returns true
.
If a value can be converted to true
, the value is so-called truthy. If a value can be converted to false
, the value is so-called falsy.
Examples of expressions that can be converted to false are:
-
null
; -
NaN
; -
0
; - empty string (
""
or ''
or ``
); -
undefined
.
Even though the !
operator can be used with operands that are not Boolean values, it can still be considered a boolean operator since its return value can always be converted to a boolean primitive. To explicitly convert its return value (or any expression in general) to the corresponding boolean value, use a double NOT operator (!!
) or the Boolean
constructor.