Home > Blockchain >  string concatenation and addition
string concatenation and addition

Time:02-12

When I try to do addition:

let x = "5"   2   3;
//output 523

let x = 2   3   "5";
// output 55

I know JavaScript concatenates the integers, but I was expecting "55" in both cases.

As 2 3 will be added to 5 and then concatenated to "5". Please can someone explain to me what is happening under the hood.

I am new to JavaScript.

CodePudding user response:

The pluses are evaluated from left to right. So first "5" 2 is evaluated (result is "52"), and then "52" 3 gives "523".

  • Related