0
Why sum=x+y not working in js
If i wanna addition 1+2 give me 12 insted of 3
4 Answers
+ 7
Do sum = x + y;
And then in another line print sum
You should get 3.
Since variables in JavaScript are of "flexible" type it may be that you are using the + to concatenate the strings "1" and "2" rather than to add up the numbers 1 and 2.
+ 5
wrapped in quotes, it joins/concatenates both strings:
"1" + "2" = "12"
Without quotes, they act like numbers that have the ability of addition:
1 + 2 = 3
If you wanna convert "12" into a number, either write it without quotes, or use parseInt("12") to get the number 12, or parseFloat if you wanna get the decimal points as well.
+ 4
Your code attempt