how to add two numbers in javascript
snippet in javascript

how to add two numbers in javascript

user3902

let a = 4;
let b = 5;
document.write(a + b);

add variable numerically in javascript

user9415

//use parseFloat(x); to change string to number
a=10;
b=20;
console.log(parseFloat(a)+parseFloat(b));//this will give a+b=30
//while
consle.log(a+b); //will give a+b=1020 [as String]

adding numbers in Javscript

user7889


 var x = 5;         // assign the value 5 to 
 x

 var y = 2;         // assign the value 
 2 to y

 var z = x + y;     // assign the value 7 to z (x + y)
 

javascript function to add two numbers

user4569

<!--Add two integer numbers using JavaScript.-->
<html>
	<head>
		<title>Add two integer numbers using JavaScript.</title>
		<script type="text/javascript">
			function addTwoNumbers(textBox1, textBox2){
				var x=document.getElementById(textBox1).value;
				var y=document.getElementById(textBox2).value;
				var sum=0;
				sum=Number(x)+Number(y);
				alert("SUM is: " + sum);
			}
		</script>
	</head>
<body>
	<h1>Add two integer numbers using JavaScript.</h1>
	<b>Enter first Number: </b><br>
	<input type="text" id="textIn1"/><br>
	<b>Enter second Number: </b><br>
	<input type="text" id="textIn2"/><br><br>
	<input type="button" id="btnSum" value="Calculate SUM" onClick="addTwoNumbers('textIn1','textIn2')"/>
</body>

</html>

add two numbers javascript

user8053

var x = 2 + 3;
//x = 5

how to add 2 numbers together in javascript

user1070

var x = +y + +z;