Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Primitive Data Types · Lesson 11 of 15

Numbers

A free lesson from Swipe Coding · JavaScript, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
One number type to rule them all — no int vs double juggling here. 🔢

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"
typeof reports the same type, "number", for both the whole number and the decimal.

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
Division always keeps decimals, since JavaScript has no separate whole-number division like Java's int / int.
🤖
NaN might be the most confusingly-named value in JavaScript. Buckle up. 😵

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);  // NaN
Both operations fail to produce a meaningful number, so JavaScript returns NaN.
Fill in the blank

Dividing zero by zero, or performing math on non-numeric data, produces the special value ____.

Quick check

Which statement about JavaScript's number type is true?

True or false

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 →