ES6 Arrow Functions in JavaScript
Arrow functions are new alternative way to create functions in JavaScript. Arrow function expression were introduced in ES6.
Arrow functions actually allow us to create shorter function syntax compared to regular functions. Also Arrow function do not have their own binding of this
for all the difference of regular and arrow functions read Difference between ES6 Arrow functions and Regular functions in JavaScript
Regular functions
function hello(name) {
console.log(name);
}
We also write function as like below
const hello = function(name) {
console.log(name);
}
Convert regular function to Arrow function
Time to convert your regular function to Arrow function expression
// removed function and added Arrow after argument
const hello = (name) => {
console.log(name);
}
Yes, now we created Arrow function. No more need to add function keyword in your JavaScript functions.
Different type of Arrow function declaration
Now again we going to short function expression.