MDN self-hosted library · e01.org

Basic math in JavaScript — numbers and operators

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
   const myInt = 5;
   const myFloat = 6.667;
   myInt;
   myFloat;
js
   typeof myInt;
   typeof myFloat;
js
const lotsOfDecimal = 1.7665849587;
lotsOfDecimal;
const twoDecimalPlaces = lotsOfDecimal.toFixed(2);
twoDecimalPlaces;
js
let myNumber = "74";
myNumber += 3;
js
typeof myNumber;
js
let myNumber = "74";
myNumber = Number(myNumber) + 3;
js
   10 + 7;
   9 * 8;
   60 % 3;
js
   const num1 = 10;
   const num2 = 50;
   9 * num1;
   num1 ** 3;
   num2 / num1;
js
   5 + 10 * 3;
   (num2 % 9) * num1;
   num2 + num1 / 8 + 2;
js
num2 + num1 / 8 + 2;
js
(num2 + num1) / (8 + 2);
js
2 + 3 ** 2;
js
4 + 2 ** 3;
(4 + 2) ** 3;
js
guessCount++;