Ad 1. null
is not an identifier for a property of the global object, like undefined
can be
let x; // undefined_x000D_
let y=null; // null_x000D_
let z=3; // has value_x000D_
// 'w' // is undeclared_x000D_
_x000D_
if(!x) console.log('x is null or undefined');_x000D_
if(!y) console.log('y is null or undefined');_x000D_
if(!z) console.log('z is null or undefined');_x000D_
_x000D_
try { if(w) 0 } catch(e) { console.log('w is undeclared') }_x000D_
// typeof not throw exception for undelared variabels_x000D_
if(typeof w === 'undefined') console.log('w is undefined');
_x000D_
Ad 2. The ===
check values and types. The ==
dont require same types and made implicit conversion before comparison (using .valueOf()
and .toString()
). Here you have all (src):
if
== (its negation !=)
=== (its negation !==)