1, the input is a string, and the connector of the string is also a plus sign. Finally, it is calculated according to the string, so it is converted into a numerical type first.
integer:c = parse int(a)+parse int(b)
Floating point number: c =parseFloat(a)+parseFloat(b)
2. You can calculate a string and execute the JavaScript code in it.
Level (a+b)
For example:
var a = 1,?
var b = 2,?
var c = a + b,
Thus, the solution of C is 12.
Use the Number () function to solve this problem, as follows:
Var c = number (a)+number (b)?
In this way, the solution of c is 3.
Extended data
Summary of addition operators in Javascript;
1, string+string
var a = ' 10 ',
b = ' 20
console . log(a+b); ? // 1020
2. String+object
var a = ' 10 ',
b = { _ key:20 };
console . log(a+b); ? // 10[ object object]
//Object.prototype.toString () method returns a string representing an object.
3. String+number
var a = ' 10 ',
b = 20
console . log(a+b); ? // 1020
var a = 10,
b = ' 20
console . log(a+b); ? // 1020