Skip to main content
Module 2 · Lesson 3 of 47/32 in the course~16 min
Module lessons (3/4)

Numbers and Math

Lesson preview5 hands-on exercises readyJavaScript Course · Module 2 — Strings and numbers

Integers and decimals, rounding, Math.min/max/round/floor/ceil, Math.random.

What you'll learn in this lesson

  • Understand the single type number (IEEE-754 64-bit) including the special values Infinity and NaN.
  • Use the main methods of Math (min, max, abs, round, floor, ceil, sqrt).
  • Generate uniform pseudorandom integers in the range [min, max].
  • Avoid binary rounding errors (0.1 + 0.2) by working with tolerances, toFixed, or whole cents.

Overview

JavaScript uses one standard numeric type (number, 64-bit IEEE-754) for both integers and decimals. This simplifies the syntax, but requires attention to two critical aspects: the statistical functions of Math and binary floating-point arithmetic.

In the actual calculation of carts and invoices, the amounts are added to .reduce() and rounded only at the time of presentation or checkout.

Sections covered in this lesson

  1. 1Mental model: Math and binary precision
  2. 2Progressive examples
  3. 3Guided laboratory
  4. 4Check for understanding
Pro Lesson · Module 2 — Strings and numbers

Unlock "Numbers and Math" and the full JavaScript Course curriculum

Integers and decimals, rounding, Math.min/max/round/floor/ceil, Math.random.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in JavaScript Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.