JavaScript兩數相加(踩坑)記錄

rgqancy發表於2017-04-17

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 +")";

相關文章