Skip to content

JavaScript Add Two Numbers

Ramesh Fadatare edited this page Aug 11, 2020 · 1 revision

In this source code example, you will learn how to add two numbers and display their sum in JavaScript. We use the addition operator + to add two or more numbers.

JavaScript Add Two Numbers

function add(num1, num2){
// add two numbers
	return num1 + num2;	
}

let num1 = 10;
let num2 = 20;

let sum = add(num1, num2);

// display the sum
console.log('The sum of ' + num1 + ' and ' + num2 + ' is: ' + sum);

Output

The sum of 10 and 20 is: 30
Clone this wiki locally