search

Home  >  Q&A  >  body text

关于定义变量的问题,然后赋值求和,出现了问题,求解释?

var mynum,mymun,sum;
mynum="8"; mymun="7"; 
sum=mynum+mymun;
document.write(sum);

为啥输出的结果是87,不是15


checkcheck2885 days ago935

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:19:14

    About the problem of defining variables, then assigning values ​​and summing, a problem occurs, please explain? -PHP Chinese website Q&A-About the problem of defining variables, then assigning values ​​and summing, a problem occurs, please explain? -PHP Chinese website Q&A

    Please watch and learn.

    reply
    0
  • 迷茫

    迷茫2016-12-21 09:41:44

    问题出在你定义mynum="8"; mymun="7"; 

    也就是说你将mynum定义为字符“8”,而非数字8,这两者是有完全不同的。mynun同理。

    解决方法:mynum = 8 ; mymun = 7 ;


    reply
    2
  • Cancelreply