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 +")";
JavaScript裡兩個變數
var a = 2;
var b = 1;
var c = "(" + a + b +")";
alert(c);
結果輸出:(21)
正確寫法:
var c = + a + + b;
var d = "(" + c +")";