===

// All of these evaluate to 'true'!
// type coercion automatically
console.log(false == '0');
console.log(null == undefined);
console.log(" \t\r\n" == 0);
console.log('' == 0);

// And these do too!
if ({}) // ...
if ([]) // ...
  • Both {} and [] are objects, and any object will be coerced to a boolean value of true in JavaScript.

  • Prefer to use === and !== to avoid any unintended side-effects of type coercion.

NaN

console.log(NaN == NaN);    // false
console.log(NaN === NaN);   // false
console.log(isNaN(NaN));    // true

Last updated

Was this helpful?