Curriculum Series

What is an arrow function?

What is an arrow function?

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
1// Traditional Function
2function multiplyBy2(input) {
3 return input * 2;
4}

Arrow Function

JAVASCRIPT
1// Remove the word "function" and place arrow between the argument and opening body bracket
2const multiplyBy2 = (input) => {
3 return input * 2;
4};
JAVASCRIPT
1// Remove the body brackets and word "return" -- the return is implied
2const multiplyBy2 = (input) => input * 2;
JAVASCRIPT
1// Remove the argument parenthesis
2const multiplyBy2 = (input) => input * 2;
JAVASCRIPT
1const output = multiplayBy2(3); // 6

Finished reading?

Mark this topic as solved to track your progress.