| null | undefined | |
|---|---|---|
| means | Assigned value, means nothing needs explicit assignment | Variable declared, but not defined. Variable's default value. |
| typeof | object | undefined |
var a; //undefined
var b = null; //null
null = 'value' //Reference error
undefined = 'value' //valuenull == undefined //true
null === undefined //false
null == 0 //falsevar undefined = null;
undefined === null //trueundefined is the only value that can't get explicitly passed in for a default-value parameter
function foo(a = 2) {
console.log(a);
}
foo(null); // null
foo(undefined); // 2