JS Built-ins
NumberparseIntbeginner

Number.parseInt() β€” '42' β†’ 42

πŸ“– Usage Example
// Parse a string to an integer with optional base
Number.parseInt('42px')       // β†’ 42
Number.parseInt('0xff', 16)   // β†’ 255
Number.parseInt('10', 2)      // β†’ 2

Use Number.parseInt() to convert a string to an integer, optionally specifying a radix for binary, octal, or hexadecimal input.

Number.parseInt()

Number.parseInt(string, radix) parses a string and returns an integer. It is the same as the global parseInt().

Number.parseInt('42')  // β†’ 42
πŸ’‘ Hints (1)
  • β€’ Always specify the radix to avoid ambiguity.