What is an arrow function?
JavaScript
Arrow Functions
An arrow function is a compact alternative to traditional function.
- they are more concise than the tranditional functions
- they manage 'this' keyword differently
Traditional Function
javascript
// Traditional Functionfunction multiplyBy2(input) {return input * 2;}
Arrow Function
javascript
// Remove the word "function" and place arrow between the argument and opening body bracketconst multiplyBy2 = (input) => {return input * 2;};
javascript
// Remove the body brackets and word "return" -- the return is impliedconst multiplyBy2 = (input) => input * 2;
javascript
// Remove the argument parenthesisconst multiplyBy2 = (input) => input * 2;
javascript
const output = multiplayBy2(3); // 6