ES6 arrow function
Arrow functions allow us to write shorter function syntax:
function sum (a, b) {
return a * b;
}
Using arrow function
const sum = (day) => {
return a * b;
}
The handling of this
is also different in arrow functions compared to regular functions.
In short, with arrow functions there are no binding of this
.
In regular functions the this
keyword represented the object that called the function, which could be the window, the document, a button or whatever.
With arrow functions the this keyword always represents the object that defined the arrow function.