Starlit Daily

📚 › JavaScript: make pages do things

8. Arrow functions

An arrow function is a short way to write a function: (a, b) => a + b. With one expression, the return is implied.

Arrow functions are common in modern code, for example inside forEach and map.

Show example

const add = (a, b) => a + b;
console.log(add(2, 3));

✍️ Your turn

Write an arrow function square that returns n times n, then print square(7).

← Back to course