Javascript’s null vs undefined

If we draw a comparison between ‘null’ and ‘undefined’, we will get following result:

null  !== undefined     true
null  !=    undefined    false
null ==    undefined   true
null === undefined   false
typeof null                  “object”
typeof undefine”      “undefined”

Undefined means a variable has been declared but has not yet been assigned a value (defined). Or we can take it as default value of variables given by JS engine until it is assigned value. (think about missed arguments when function is called, absent property of an object). It means nothing.

Null is an assignment value. It can be assigned to a variable as “no value” or “empty object”. It has to be assign programmatically but not default set. (think about DOM operation returns an object reference either a element or null). It means a value

In conclusion, both null and undefined mean nothing, are falsey (type coercion), so null abstractly (loosely) equals to undefined, however their types are different, so null strictly does not equal to undefined.

Javascript’s null vs undefined