There are several differences between null and undefined, which are sometimes understood as the same.
Undefined: It means the value does not exist in the compiler. It is the global object.
You can see refer to “==” vs “===” article.
null == undefined // true null === undefined // false
It means null is equal to undefined but not identical.
When we define a variable to undefined then we are trying to convey that the variable does not exist .
When we define a variable to null then we are trying to convey that the variable is empty.
Differentiating using isNaN():
You can refer to NaN article for better
isNaN(2 + null) // false isNaN(2 + undefined) // true
null ? console.log("true") : console.log("false") // false
Null is also referred as false.
When variable is not assigned a value
var temp; if(temp === undefined) console.log("true"); else console.log("false");
Accessing values which does not exist
var temp=['a','b','c']; if(temp === undefined) console.log("true"); else console.log("false");