We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Arrow Functions

Fat arrow functions, or "arrow functions" are another way to define functions in JavaScript. Arrow functions are newer than the function keyword, however, unlike the let/const syntax, arrow functions are sometimes better, not always better.

// declaring a function without a variable
function add(x, y) {
  return x + y;
}
// declaring a function with a variable
const add = function (x, y) {
  return x + y;
};
// using the fat arrow syntax
const add = (x, y) => {
  return x + y;
};

It's so cool and not confusing at all that there are 3 ways to do (basically) the same thing...

What's the Difference?

  • Fat arrow functions are usually declared as variables, while the function keyword may or may not be declared as a variable.
  • Fat arrow functions handle object scoping in a more intuitive way (we'll talk about this later)
  • Fat arrow functions don't work as constructors (we'll talk about this later)
  • Other minor differences

Assignment

You just got a new zoomer boss at Textio that thinks fat arrow functions are the best thing since Mr. Beast's last video. He's forcing the team to convert all the classic functions to fat arrow functions.

Convert isSpamMessage to the fat arrow function syntax, but don't change its internal behavior.