JavaScript has one standard number type for both integers and decimals, stored in 64-bit IEEE 754 floating-point format. Numbers also include three special values: Infinity, -Infinity, and NaN (Not a Number).
Because 64-bit floats reserve bits for exponents and signs, exact integer math works reliably up to Number.MAX_SAFE_INTEGER (9,007,199,254,740,991). Above that boundary, consecutive integers lose precision and round to even values.
Modern JavaScript (ES2021) also lets you write underscores inside large numbers as visual separators, such as 1_000_000, which engines ignore during execution.
NaN, and InfinityAlways use Number.isNaN() instead of global isNaN(), because global isNaN("abc") coerces strings first and returns misleading results.
const annualBudget = 1_500_000;
const badMath = Number("abc"); // NaN
console.log("Budget:", annualBudget);
console.log("Is NaN strictly:", Number.isNaN(badMath)); // true
console.log("NaN === NaN:", badMath === badMath); // false!
// Fix binary decimal drift when comparing floats
const sum = 0.1 + 0.2;
const isClose = Math.abs(sum - 0.3) < Number.EPSILON;
console.log("0.1 + 0.2 close to 0.3:", isClose);
x === NaN: NaN is the only value in JavaScript not equal to itself. Always call Number.isNaN(x).===: 0.1 + 0.2 === 0.3 evaluates to false due to binary representation. Use integer cents or compare against Number.EPSILON.075: Older octal syntax causes confusion or throws a SyntaxError in strict mode. Use 0o75 for explicit octal numbers.typeof NaN return "number"?In IEEE 754 math, NaN represents an invalid numeric result inside the number type, such as 0 / 0 or Number("hello").
isNaN() and Number.isNaN()?Global isNaN("hello") converts "hello" to NaN and returns true. Number.isNaN("hello") returns false because "hello" is a string, not the NaN value.
Number to BigInt?Switch to BigInt whenever you handle integers larger than 9,007,199,254,740,991, such as 64-bit database IDs or cryptography.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.
You've completed this section! Take a quick 5-question quiz to check your understanding.