javascript (+) sign concatenates instead of giving sum?

后端 未结 7 530
旧巷少年郎
旧巷少年郎 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:37

    Who are using javascript in salesforce make sure

    var a= 8 ;
    var b =8 ;
    var c = a+b;
    

    This will give u result output = 88; It is will just concatenate. If you want to add those two: You should write logic as :

    var a = 8;
    var b = 8
    var c = parseInt(a)+ parseInt(b);
    

    This will give you the desired result of 16 , The same is the case with multiplication.

    Hope this helps.

提交回复
热议问题