Numbers & BigInt
Master this topic with zero to advance depth.
Expert Answer & Key Takeaways
Mastering Numbers & BigInt is essential for high-fidelity technical architecture and senior engineering roles in 2026.
JavaScript Numbers
JavaScript has only one type of number. Numbers can be written with, or without, decimals.
1. Numeric Literals
JavaScript numbers can be integers (without decimals) or floating-point (with decimals).
let x = 3.14; // A number with decimals
let y = 3; // A number without decimalsExtra large or extra small numbers can be written with scientific (exponent) notation:
let x = 123e5; // 12300000
let y = 123e-5; // 0.001232. JavaScript Numbers are Always 64-bit Float
Unlike many other programming languages, JavaScript does not define different types of numbers (like integers, short, long, floating-point etc).
JavaScript numbers are always stored as double precision floating point numbers, following the international IEEE 754 standard.
[!WARNING] Floating point arithmetic is not always 100% accurate. For example:0.1 + 0.2results in0.30000000000000004.
3. Precision
Integers are accurate up to 15 digits. The maximum number of decimals is 17.
4. Adding Numbers and Strings
JavaScript uses the
+ operator for both addition and concatenation. If you add two numbers, the result will be a number. If you add two strings, the result will be a string concatenation.let x = 10;
let y = 20;
let z = x + y; // z will be 30 (a number)
let a = "10";
let b = "20";
let c = a + b; // c will be "1020" (a string)If you add a number and a string, the result will be a string concatenation!
5. NaN - Not a Number
NaN is a JavaScript reserved word indicating that a number is not a legal number. Trying to do arithmetic with a non-numeric string will result in NaN:let x = 100 / "Apple"; // x will be NaN (Not a Number)6. Infinity
Infinity (or -Infinity) is the value JavaScript will return if you calculate a number outside the largest possible number.let x = 2 / 0; // x will be Infinity
let y = -2 / 0; // y will be -InfinityTop Interview Questions
?Interview Question
Q:Why does 0.1 + 0.2 not equal 0.3 in JavaScript?
A:
This is due to the IEEE 754 floating-point standard used by JavaScript. Numbers are represented in binary internally, and some decimal fractions (like 0.1) cannot be represented with perfect precision in binary, leading to tiny rounding differences.
?Interview Question
Q:What is NaN in JavaScript?
A:
NaN stands for 'Not a Number'. It is a value that indicates a numerical operation failed or resulted in an undefined mathematical result (e.g., dividing a number by a string).
?Interview Question
Q:What happens when you add a string '10' and a number 5?
A:
JavaScript will perform concatenation instead of addition, resulting in the string '105'.
Course4All Engineering Team
Verified ExpertSenior Full-Stack Engineers & V8 Experts
Our JavaScript and engine-level content is developed by a collective of senior engineers focused on high-performance web architecture and 2026 standards.
Pattern: 2026 Ready
Updated: Weekly
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.