#34: parseInt('08')
Topic: numbers · Difficulty: ★
console.log(parseInt('08'));Output
8
Why
In old (pre-ES5) JavaScript engines, parseInt would sometimes treat a leading zero as an octal prefix and try to parse '08' as base 8 — which would fail because 8 isn't a valid octal digit, often yielding 0 or NaN depending on the engine. Since ECMAScript 5, parseInt without an explicit radix argument always defaults to base 10 when the string doesn't start with '0x' or '0X', so '08' parses cleanly as decimal 8. Old tutorials warning you to always pass a radix are mostly addressing this now-fixed legacy behavior.