JS Foundations #10 — Numbers & Math

IEEE 754 floating point, NaN, Infinity, +0/-0, Number.isNaN vs isNaN, Number.isFinite, and every Math method you'll reach for — with the traps interviewers test.

8 min read
JavaScript
Fundamentals
Numbers
Math

TABLE OF CONTENTS

JavaScript has one number type — IEEE 754 double-precision 64-bit floating point. That single fact explains NaN, Infinity, 0.1 + 0.2 !== 0.3, and +0/-0. This article covers Number methods, the Math object, and the traps interviewers test.


1. Number Representation

JavaScript uses 64-bit IEEE 754. Integers are safe up to 2^53 - 1; beyond that precision degrades.

Loading editor...

For integers larger than MAX_SAFE_INTEGER, use BigInt:

Loading editor...


2. NaN — Not a Number

NaN is the result of a failed numeric operation. It's the only value not equal to itself.

Loading editor...

Interview use: Deep equality checks (#14), JSON.stringify (NaN → null).


3. Infinity and Finite Checks

Loading editor...

Interview use: JSON.stringify (Infinity → null), range checks (#30).


4. +0 and -0

IEEE 754 has signed zero. +0 === -0 is true, but Object.is(+0, -0) is false.

Loading editor...

Interview use: Deep equality — Object.is or custom check (#14).


5. Floating-Point Precision

0.1 + 0.2 is not 0.3 — it's a binary representation artifact:

Loading editor...


6. Number Static Methods

Number.isInteger(value) — Integer Check

Loading editor...

Number.parseFloat(str) / Number.parseInt(str, radix)

Loading editor...

Number.prototype.toFixed(digits) — Format

Loading editor...


7. The Math Object

Rounding

Loading editor...

Min, Max, Range

Loading editor...

Interview use: Range filters in data selection (#30).

Random

Loading editor...

Other Useful Math Methods

Loading editor...


Quick Reference

CategoryMethods
CheckNumber.isNaN(v), Number.isFinite(v), Number.isInteger(v), Number.isSafeInteger(v)
ParseNumber.parseInt(s, r), Number.parseFloat(s)
RoundMath.floor, Math.ceil, Math.round, Math.trunc
Min/MaxMath.min(...a), Math.max(...a)
RandomMath.random()
OtherMath.abs, Math.sqrt, Math.pow, Math.sign
EqualityObject.is(a, b) — handles NaN and +0/-0 correctly

Interview Tips

  • Use Number.isNaN, not isNaN — the global version coerces strings to numbers.
  • Use Number.isFinite, not isFinite — same reason.
  • Use Object.is for strict comparisons — handles NaN and signed zero.
  • Clamp with Math.min(Math.max(v, min), max) — the one-liner for range constraints.

Related Articles


Let's Connect

© 2026 Naveen Karthik // Built with React & MUI