null represents “no value,” meaning “nothing,” not even an empty string or zero.
It’s used as a placeholder in a variable to let you know there’s nothing useful in there.
It’s a reference to nothing.
When a variable is assigned null, it does not contain any valid data type.
It can be used to initialise a variable so that it does not produce errors or to clear the value of a variable, so that there is no longer any data associated with that variable, and the memory used by it is freed by the garbage collector
A variable that has been declared, but given no initial value, contains the value undefined and will produce a runtime error if you try to use it.
The difference between null and undefined is subtle.
If nothing (not even
null) has ever been stored in a variable, then it’s
undefined, but for convenience, much of the time it acts as if it had a
If compared with the == equality operators, null and undefined are equal, but if compared with the === identity operator, they are not identical.
NaN means ‘Not a Number’ and is the result of a mathematical operation that makes no sense.