javascript (+) sign concatenates instead of giving sum?

后端 未结 7 502
旧巷少年郎
旧巷少年郎 2020-12-07 03:41

I created a simple program that make the sum of two numbers BUT.. the program is concatenating instead, This is so confusing! Can anyone help?

相关标签:
7条回答
  • 2020-12-07 04:40

    Here value gives you a string, hence the concatenation. Try parsing it as an Number instead:

    var sum = parseInt(numberOne) + parseInt(numberTwo);
    

    See the demo fiddle.

    0 讨论(0)
提交回复
热议问题