xxxxxxxxxx
null is a special object because typeof null returns 'object'.
On the other hand,
undefined means that the variable has not been declared,
or has not been given a value.
xxxxxxxxxx
What is the Difference between Undefined, undeclared, Null
// undefined means that the variable has not been declared, or has not been given a value.
// Undefined is used for unintentionally missing values.
var dog;
console.log(dog);
// Undeclared means the variable does not exist in the program at all.
console.log(cat);
// Null used for intentionally missing values. It contains no value.
xxxxxxxxxx
undefined: It means a variable declared, but no value has been assigned a value.
//example:
var demo;
alert(demo); //shows undefined
alert(typeof demo); //shows undefined
null: Whereas, null in JavaScript is an assignment value.
You can assign it to a variable.
//Example:
var demo = null;
alert(demo); //shows null
alert(typeof demo); //shows object
xxxxxxxxxx
//loosely equal (compare values between two variables)
null == undefined // true ( null => 0 , undefined => NAN)
//strictly not equal (compare both type and value)
null === undefined // false (typeof null => object , typeof undefined => undefined)
null !== undefined // true (typeof null => object , typeof undefined => undefined)