JS Built-ins
TypeCoercionintermediate

Explicit Number Conversion

Number Conversion

Convert values to numbers using:

  • Number(value) - explicit conversion
  • +value - unary plus operator
  • parseInt(string, radix) - parse integer
  • parseFloat(string) - parse floating point

Key conversions:

  • Number('') is 0 (empty string coerces to 0)
  • Number(' 3 ') is 3 (whitespace is trimmed)
  • Number('abc') is NaN (non-numeric string)

Challenge: Convert empty string, a spaced number, and a non-numeric string to numbers.

πŸ’‘ Hints (4)
  • β€’ Empty strings coerce to 0.
  • β€’ Number() trims whitespace before parsing.
  • β€’ Non-numeric strings result in NaN, not a SyntaxError.
  • β€’ Use Number.isNaN() to check for NaN values.