Function Expression
Function Expression is another way to define a function in JavaScript. Here we define a function using a variable and store the returned value in that variable.
Example: Below is an example that illustrates the use of Function Expression.
Javascript
// Function Expression const add = function (a, b) { console.log(a + b); } // Calling function add(2, 3); |
Output
5
Here, the whole function is an expression and the returned value is stored in the variable. We use the variable name to call the function.
Different ways of writing functions in JavaScript
JavaScript Function is a block of code that is designed to perform a task and executed when it is been called or invoked.
Below are the ways of writing functions in JavaScript:
Table of Content
- Function Declaration
- Function Expression
- Arrow Functions
Contact Us