JS Built-ins
Numberbeginner

Number() β€” null becomes 0

πŸ“– Usage Example
// Convert a value to a number
Number('42')    // β†’ 42
Number(true)    // β†’ 1
Number(false)   // β†’ 0
Number('')      // β†’ 0

Use the Number() function to explicitly convert a value to a numeric type, which is more predictable than implicit coercion.

Number() β€” null Coercion

Number(null) returns 0 (not NaN!).

Challenge: Verify this behaviour.

πŸ’‘ Hints (1)
  • β€’ `null` is coerced to `0`, unlike `undefined` which gives `NaN`.