JS Built-ins
TypeCoercionbeginner

Null and Undefined Coercion

Null and Undefined Type Coercion

  • null coerces to 0 in numeric context: +null is 0
  • undefined coerces to NaN in numeric context: +undefined is NaN
  • Both null and undefined are falsy: !null is true, !undefined is true

Challenge: Return an object showing numeric and boolean coercion of null and undefined.

πŸ’‘ Hints (4)
  • β€’ The unary + operator coerces to number.
  • β€’ null coerces to 0, but undefined coerces to NaN.
  • β€’ Use Number.isNaN() to check for NaN.
  • β€’ Both null and undefined are falsy values.