Null Type Coercion

Javascript converts value types on the fly as needed. It's called "type coercion". If you're not aware of this, you may inadvertently introduce bugs to your code. To avoid this issue all together, you can use strict ( === ) comparisons liberally. In fact JSLint will insist that you do. Though, sometimes you can leverage type coercion. For instance, null & undefined values will convert to false when compared. The following:

if (x == null){}

is much more concise than:

if (x === null || x === undefined){}

As a front-end developer you should make it a point to have good understanding of type coercion. If you find yourself having a difficult time explaining the concept to back-end developer or someone who's learning, use a visual:

  var n = null, nn; // nn is undefined
  
  if (n == null) { document.write(true); } else { document.write(false) }
  
  if (n === null) { document.write(true); } else { document.write(false) }
  
  if (nn == null) { document.write(true); } else { document.write(false) }
  
  if (nn === null) { document.write(true); } else { document.write(false) }
  

=== knows the difference

== does not