How to use function In Javascript
In this approach, we are adding two numbers using a function in JavaScript involves defining a custom function that takes two parameters, adds them, and returns the result.
Syntax:
function additionFunction(a, b) {
return a + b;
}
Example: In this example we are using the above-explained approach.
function additionFunction(a, b) {
return a + b;
}
let num1 = 5;
let num2 = 10;
let sum = additionFunction(num1, num2);
console.log("Sum of given numbers is :", sum);
Output
Sum of given numbers is : 15
JavaScript Program to Add Two Numbers
We will explore how to add two numbers in JavaScript. Adding two numbers in JavaScript means combining numeric values together using arithmetic addition, which gives us their total sum.
There are several methods that can be used to Add Two Numbers in JavaScript, which are listed below:
Table of Content
- Using + Operator
- Using function
- Using Arrow function
- Using Addition Assignment (+=) Operator