How to add two variables?? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

How to add two variables??

var a = 2 var b = 3 document.write(a+b) Output is 23, And i want it to be 5

9th May 2022, 4:02 AM
Pe Steve
Pe Steve - avatar
4 Antworten
+ 2
Basic JavaScript Addition:- var x = 1; var y = 2; var result = x + y; The result is "3".Add numbers in JavaScript by placing a plus sign between them.
9th May 2022, 4:23 AM
Sachin Bhujel
Sachin Bhujel - avatar
+ 1
I believe you put the 2 and 3 in quotation marks (“2” and “3”) which will do something called concatenation so that it returns 23. If you want the mathematical addition, do not put them in quotation marks
9th May 2022, 7:28 AM
Kamil Hamid
Kamil Hamid - avatar
0
For js : use console.log(a+b); but that also outputs 5. check again...
9th May 2022, 8:56 AM
Jayakrishna 🇮🇳
0
How are you getting 23? The code you have shown will output 5.
10th May 2022, 1:07 AM
Chris Coder
Chris Coder - avatar