JavaScript
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
Related JavaScript interview topics
Continue with nearby questions from the same topic cluster.