What is null?
- Null must be assigned.
let a = null; //output: null console.log(a);
//output: false console.log(Boolean(null))
let a = null; let nullType = typeof(a); //output: "object" console.log(nullType);
What is undefined?
let newVar; //output: "undefined" console.log(newVar);
//output: false console.log(Boolean(undefined))
- You can also assign undefined value to a variable explicitly.
var newVar = undefined; //output: false console.log(newVar);
var newVar = undefined; //output: true console.log(typeof(newVar) === 'undefined');
Operations between null and undefined
//"object" (for legacy reasons) typeof null //"undefined" typeof undefined //false as both are of different types null === undefined //true null == undefined