JavaScript typeof, null, undefined, valueOf().
You can use the JavaScript typeof operator to find the type of a JavaScript variable.
![]() |
In JavaScript, an array is a special type of object. Therefore typeof [1,2,3,4] returns object. |
---|
In JavaScript null is "nothing". It is supposed to be something that doesn't exist.
Unfortunately, in JavaScript, the data type of null is an object.
![]() |
You can consider it a bug in JavaScript that typeof null is an object. It should be null. |
---|
You can empty an object by setting it to null:
You can also empty an object by setting it to undefined:
In JavaScript, undefined is a variable with no value.
The typeof a variable with no value is also undefined.
Any variable can be emptied, by setting the value to undefined. The type will also be undefined.