If you’ve ever encountered the puzzling behavior of parseInt('09') returning 0 in JavaScript, you’re not alone. This quirk stems from how JavaScript’s parseInt() function handles numeric strings with leading zeros. Meanwhile, if you’re a developer or entrepreneur looking for where to build mobile apps in Abuja, Nigeria, See some of the projects we’ve worked on and contact us here.
parseInt('09') Return 0?parseInt() WorksJavaScript’s parseInt() converts a string to an integer, but it has a few unexpected behaviors:
0x or 0X, it’s parsed as hexadecimal (base 16).0 (but not 0x), older JavaScript engines (pre-ES5) treated it as octal (base 8).parseInt('09')09 was interpreted as an octal number, but 9 is invalid in octal (digits must be 0-7).9 isn’t a valid octal digit, parseInt() stops parsing and returns 0.To avoid ambiguity, always pass the radix (base) as the second argument:
parseInt('09', 10); // Correct: returns 9
parseInt('0x10', 16); // Correct: returns 16 parseInt()Number() – Converts strings directly to numbers (doesn’t handle hex/octal ambiguity). Number('09'); // Returns 9 + Operator – A shorthand for Number(). +'09'; // Returns 9 While debugging JavaScript quirks is essential, if you’re looking to build a mobile app in Abuja, here are the best places to turn your idea into reality, check some of the projects we have worked on and reach out to us.
Understanding JavaScript quirks like parseInt('09') helps prevent bugs in your code. Meanwhile, if you’re searching for where to build mobile apps in Abuja, Nigeria, Codeflare offers a thriving tech ecosystem with skilled developers and innovators ready to bring your project to life.
Latest tech news and coding tips.
1. What Is the Golden Ratio? The Golden Ratio, represented by the Greek letter φ (phi), is…
In CSS, combinators define relationships between selectors. Instead of selecting elements individually, combinators allow you to target elements based…
Below is a comprehensive, beginner-friendly, yet deeply detailed guide to Boolean Algebra, complete with definitions, laws,…
Debugging your own code is hard enough — debugging someone else’s code is a whole…
Git is a free, open-source distributed version control system created by Linus Torvalds.It helps developers: Learn how to…
Bubble Sort is one of the simplest sorting algorithms in computer science. Although it’s not…