Numbers
A free lesson from Swipe Coding · JavaScript, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
JavaScript has just one numeric type, called number, covering both whole numbers and decimals. Unlike Java, there's no separate int vs double — 5, 5.0, and 5.5 are all simply a number.
const wholeNumber = 10; const decimalNumber = 4.99; console.log(typeof wholeNumber, typeof decimalNumber); // "number" "number"
The basic arithmetic operators are + (add), - (subtract), * (multiply), / (divide), % (remainder, also called modulo), and ** (exponent).
console.log(10 + 3); // 13 console.log(10 - 3); // 7 console.log(10 * 3); // 30 console.log(10 / 3); // 3.3333333333333335 console.log(10 % 3); // 1
NaN stands for "Not a Number" — a special number value produced by an invalid math operation, such as dividing zero by zero or trying to do arithmetic with something that has no meaningful numeric value. Confusingly, typeof NaN is itself "number".
console.log(0 / 0); // NaN
console.log("abc" * 2); // NaNDividing zero by zero, or performing math on non-numeric data, produces the special value ____.
Which statement about JavaScript's number type is true?
In JavaScript, 5 and 5.0 are stored using the exact same number type.
Keep your streak going in Swipe Coding
Swipe through every level of JavaScript on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →