When Arrows Aren't Just a Shortcut

Arrow functions have several important differences from regular ones:

1. No " this " of their own

Arrow functions do not have their own this context. If you use this inside an arrow function, it is taken from the outer function. This is very useful when working with events and timers.

2. Multi-line Arrows

If you need more than one line of code, use curly braces and explicitly write return.

let sum = (a, b) => {
  let result = a + b;
  return result; // If there are {}, return is required!
};
Warning

Arrow functions do not have the arguments object. If you need to collect all arguments, use the modern rest parameters syntax ...args.