Lets see the below example:
var i = 10; typeof i; number
Then we don’t assign anything to the variable and use “typeof” statement to check the type of the variable. Below is the example:
var k; typeof k; undefined
We can use “undefined” in conditional statements also. Lets check our variables “i” and “k” are defined or not. To check this we can use “undefined” value type. Below is the example:
i==undefined; false k==undefined; true
Then, why we need “null”?
typeof null; object
If we want to unset the value of a variable, we can use “null”.
var msg="Hello, World!"; print(msg); msg=null; if ( msg == null ) print('Message not set');