1var myVar=null;
2
3if(myVar === null){
4 //I am null;
5}
6
7if (typeof myVar === 'undefined'){
8 //myVar is undefined
9}
10
1/* In Javascript,
2* null: a value explicitly set by the programmer for the intentional lack of value.
3* undefined: a value implictily or explicitly set for the intentional lack of value.
4*/
5
6console.log(null == undefined) // true
7console.log(null === undefined) // false
8
9let a = null
10console.log(a) // null
11
12let c;
13let d = undefined;
14console.log(c, d) // undefined undefined
15
16console.log(typeof null) // Object
17console.log(typeof undefined) // undefined
1Undefined used for unintentionally missing values.
2
3Null used for intentionally missing values.
1var TestVar = null;
2alert(TestVar); //shows null
3alert(typeof TestVar); //shows object
4
1//loosely equal (compare values between two variables)
2null == undefined // true ( null => 0 , undefined => NAN)
3
4//strictly not equal (compare both type and value)
5null === undefined // false (typeof null => object , typeof undefined => undefined)
6null !== undefined // true (typeof null => object , typeof undefined => undefined)
7
1var TestVar;
2alert(TestVar); //shows undefined
3alert(typeof TestVar); //shows undefined
4