Functions and Arrow Syntax

Write functions the classic way and with concise arrow syntax.

Functions are how you package up reusable behaviour. Here’s the classic declaration:

function add(a, b) {
  return a + b;
}

And the same thing as an arrow function — shorter, and handy for callbacks:

const add = (a, b) => a + b;

Arrow functions also keep the surrounding this, which avoids a whole class of bugs in callbacks.