Skip to content
Justice Tech School

Numbers

JavaScript has one number type for whole numbers and decimals. Special values are Infinity and NaN (not a number). Because numbers use binary fractions, 0.1 + 0.2 is not exactly 0.3.

For money, work in the smallest unit (kobo or cents) as whole numbers, or round the result when showing it.

Example
console.log(10 / 3);
console.log(0.1 + 0.2);
console.log((0.1 + 0.2).toFixed(2));
console.log(1 / 0);
console.log(Number("x"));
console.log(isNaN(Number("x")));

Exercise

What does dividing a number by zero give?

console.log(5 / 0); // 

Quiz Test

What does NaN stand for?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.