Sikau

JavaScript · Day 6 · about 25 min

Numbers and maths

JavaScript as a very fast calculator.

Everyday maths

Splitting a bill, working out a discount, counting days until a festival — computers do this kind of maths instantly. Today you'll learn JavaScript's maths symbols.

The maths symbols

These symbols are called operators — they operate on values.

console.log(8 + 2);   // add
console.log(8 - 2);   // subtract
console.log(8 * 2);   // multiply
console.log(8 / 2);   // divide

Numbers can have decimals too. JavaScript uses a dot, not a comma: 2.5

console.log(10 / 4);
console.log(0.1 + 0.2);

The rest of this lesson

  • Order of operationsexplain
  • The remainder: %explain
  • Decimals and rounding surprisesexplain
  • Predict the outputpredict
  • Which goes first?predict
  • Split the billwrite code
  • Brackets matterwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript