What is an arrow function?

JavaScript Important

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

// Traditional Function
function multiplyBy2(input) {
return input * 2;
}

Arrow Function

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

Table of Contents