JavaScript Add Two Numbers



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.
Check out all 100 + JavaScript Examples
Check out all JavaScript programs at All JavaScript Programs 

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

Related Examples

Check out all 100 + JavaScript Examples
Check out all JavaScript programs at All JavaScript Programs  

Comments