JavaScript Add Two Numbers - RameshMF/java-algorithms-implementation GitHub Wiki

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