Adding two numbers concatenates them instead of calculating the sum
JavaScript里两个变量
var a = 2;
var b = 1;
var c = "(" + a + b +")";
alert(c);
结果输出:(21)
正确写法:
var c = + a + + b;
var d = "(" + c +")";
时间: 2025-01-08 00:03:25
JavaScript里两个变量
var a = 2;
var b = 1;
var c = "(" + a + b +")";
alert(c);
结果输出:(21)
正确写法:
var c = + a + + b;
var d = "(" + c +")";