Tagged articles
2 articles
Page 1 of 1
JavaScript
JavaScript
Jan 4, 2022 · Frontend Development

Why parseInt Returns Unexpected Results and How to Use It Correctly

This article explains how JavaScript's parseInt function works, its handling of radix and floating‑point numbers, why it produces surprising results with very small values, and recommends safer alternatives like Math.floor for extracting integer parts.

JavaScriptMath.floorfloating-point
0 likes · 5 min read
Why parseInt Returns Unexpected Results and How to Use It Correctly
JavaScript
JavaScript
Apr 25, 2021 · Frontend Development

Why Does parseInt(0.0000005) Return 5? Uncovering JavaScript’s Quirks

This article explains JavaScript’s parseInt function, demonstrates how it parses integer strings and binary numbers, reveals its unexpected behavior with small floating‑point values due to automatic string conversion and exponential notation, and recommends using Math.floor for reliable integer extraction.

JavaScriptMath.floorparseInt
0 likes · 5 min read
Why Does parseInt(0.0000005) Return 5? Uncovering JavaScript’s Quirks