It converts the string number to actual number in the expression.
console.log(typeof +"1"); // number
console.log("1" + "1"); // 11
console.log(+"1" + +"1"); // 2
console.log("1.3" + "1.546"); // 1.31.546
console.log(+"1.3" + +"1.546"); // 2.846
Quoting from the ECMA 5.1 Standard Specifications for + operator,
The unary + operator converts its operand to Number type.
Internally, a JavaScript string will be converted to a number based on these rules specified in the ECMA 5.1 standards.
Edit: As per the Number
specifications, it also internally uses the same ToNumber
to convert its parameter to a number. So, technically Number(<number string>)
is the same as +<number string>
.