string + number
const a = "5";
const b = 7;
console.log(a + b);
Output is - 57
string * number
const a = "5";
const b = 7;
console.log(a * b);
Output is - 35
string + number
const a = "5";
const b = 7;
console.log(a + b);
Output is - 57
string * number
const a = "5";
const b = 7;
console.log(a * b);
Output is - 35
it's based on what the creators of JS thought would be more useful. In every other language you can concatenate the strings, numbers and other stuff using the +
. So in JS they thought that would be a nice solution as well. But then... what does it mean to multiply a string? The creators of JS had no answer, so assumed this must be a mathematical operation.