This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.

Smartphone icons created by Freepik - Flaticon

JavaScript Numbers

A common mistake is to expect this result to be 102030:

let x = 10;
let y = 20;
let z = "30";
let result = x + y + z;
document.getElementById("demo").innerHTML = result;
Legend

numbers string
When numbers are added to a string, the result is a string.

  • The JavaScript interpreter works from left to right.
  • First 10 + 20 is added because x and y are both numbers.
  • Then 30 + "30" is concatenated because z is a string.