JavaScript两数相加(踩坑)记录

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

posted @ 2017-04-17 19:06  任国强  阅读(2212)  评论(0编辑  收藏  举报