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' //value
null == undefined //true
null === undefined //false
null == 0 //false
var undefined = null;
undefined === null //true
undefined 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