Amiga500
Amiga500

Reputation: 6131

parseInt - In Node environment, using radix

I was not able to find definite answer, do we still need to use radix (Node)?

let number = parseInt('666');

VS

let number = parseInt('666', 10);

Upvotes: 0

Views: 257

Answers (1)

Nina Scholz
Nina Scholz

Reputation: 386654

Form MDN to parseInt:

If radix is undefined or 0 (or absent), JavaScript assumes the following:

  • If the input string begins with "0x" or "0X", radix is 16 (hexadecimal) and the remainder of the string is parsed.

  • If the input string begins with "0", radix is eight (octal) or 10 (decimal).  Exactly which radix is chosen is implementation-dependent.  ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. For this reason always specify a radix when using parseInt.

  • If the input string begins with any other value, the radix is 10 (decimal).

Upvotes: 2

Related Questions