Numbers

medium

Complete guide with examples and interview questions · 30 min

Definition

Say it out loud in an interview — clear, simple, no textbook wording.

If someone asks how numbers work in JavaScript, I'd say there's only one number type: a 64-bit float. There is no separate int — 42 and 42.5 are the same type, which is why decimal math can surprise you.

Interviewers almost always follow up with 0.1 + 0.2 or NaN. Binary can't store 0.1 exactly — like 1/3 in decimal, it repeats forever — so the sum lands at 0.30000000000000004. And NaN is the only value in the language that isn't equal to itself.

In senior rounds you might hear about Number.EPSILON: it's the smallest step a double can take near 1, not a general-purpose comparison tolerance. Fine for numbers under 1; misleading for millions. And past Number.MAX_SAFE_INTEGER, integers start rounding too — that's what BigInt is for.

Quick Stats
30
Minutes
medium
Difficulty
5
Interview Q's

Key takeaways

  • JavaScript has one number type: IEEE 754 double-precision float
  • 0.1 + 0.2 is 0.30000000000000004 — never trust === on decimal math
  • NaN is not equal to itself; use Number.isNaN (not the coercing global)
  • Number.EPSILON is the smallest representable step, not a general comparison tolerance
  • BigInt handles integers beyond Number.MAX_SAFE_INTEGER

Track your mastery

Sign in to save Q&A scores, coding challenge progress, points, and streaks across devices.

Sign in to save progress