Skip to main content

JavaScript Numbers & Math

10 lessonsAbout 60 minutesIntermediate

This part of the JavaScript Tutorial runs from JavaScript Numbers through to JavaScript Integer Safety. There are 10 lessons here, and working through them takes about 60 minutes at a steady pace.

It follows on from JavaScript Strings, so finish that first if you have not already — the examples below assume you are comfortable with it.

Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.

  1. 1JavaScript NumbersJavaScript has a single number type covering both whole numbers and decimals.
  2. 2JavaScript Number MethodsNumber methods format and convert numbers, always returning a new value.
  3. 3JavaScript parseInt and parseFloatparseInt and parseFloat read a number from the start of a string.
  4. 4JavaScript Number PrecisionDecimal arithmetic in JavaScript is not always exact, which is why 0.1 plus 0.2 is not 0.3.
  5. 5JavaScript Math ObjectMath is a built-in object holding mathematical constants and functions.
  6. 6JavaScript Math Roundinground, floor, ceil and trunc turn a decimal into a whole number in different ways.
  7. 7JavaScript Math.randomMath.random gives a random decimal between 0 and 1.
  8. 8JavaScript Math.min and Math.maxMath.min and Math.max find the smallest and largest of the values you give them.
  9. 9JavaScript Number FormattingtoLocaleString formats numbers as currency, percentages and grouped digits.
  10. 10JavaScript Integer SafetyJavaScript numbers are only exact up to a certain size, after which BigInt takes over.