When assigned to a variable, it means no value is available yet for that variable.
Difference Between Null & Undefined
The difference between null
can be a bit confusing since both depict variables without values but then, the difference between undefined
On the other hand, null
to show we are aware of the existence of the variable without a value for it.
var x = null;
We also use null
to remove or offset the value of a variable if we no longer need that value.
var arr = [1, 2, 3]; //arr contains an array
arr = null; //arr is now null or empty
|Data type is object||Data type is undefined.|
|null is a reserved keyword.||undefined is not a reserved keyword.|
Every variable that is assigned null
has an object. Nevertheless, it is an empty object which have no properties or methods that can be used in manipulating null
Using the typeof operator on a variable assigned the value, null
will return object
but then, it is an empty object.
According to JS history, null
is an object
- Null is a value assigned to a variable to depict absence of a value.
- The typeof operator will return null when used on null.