In this example, you will learn about JavaScript arrow function.
Arrow function is one of the features introduced in the ES6 version of JavaScript. It allows you to create functions easy way compared to regular functions.
Regular Function
// regular function
let result = function(a, b) {
return a + b;
}
ES6 Arrow Function
// arrow function
let result = (a, b) => a + b;
Arrow Function Syntax
The syntax of the arrow function look like is:
let myFunction = (arg1, arg2, ...argN) => {
statement...
}
Here,
- myFunction is the function name
- arg1, arg2,...argN is the argument(parameter) of the function
- statement... is the body of the function
Comments
Post a Comment