0

Why is parseInt() returning 23 for values / numbers greater than 23? Seeing this strange behaviour and not sure why is this happening? Can someone help me explain why?

console.log(parseInt(null, 10));
console.log(parseInt(null, 23));
console.log(parseInt(null, 24));
console.log(parseInt(null, 30));
Milan Chheda
  • 8,159
  • 3
  • 20
  • 35
  • You know you are setting the 'radix' of the function parseInt, right? See https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/parseInt – Marco de Zeeuw Jul 29 '17 at 12:22
  • Yes, I know first argument is number, but this is something that just got discovered while working on something and was wondering why is it happening? – Milan Chheda Jul 29 '17 at 12:24
  • it changes after base 30 (on mozilla). check different browsers' js engine source code, how and why they've implemented such way -)) – marmeladze Jul 29 '17 at 12:25
  • this is the same as `parseInt('n', 23)`, see duplicate – Pac0 Jul 30 '18 at 14:22

0 Answers0