Arrow Functions
A shorter syntax.
Modern JavaScript has a shorter way to write functions, using an arrow made of an equals sign and a greater than sign. Arrow functions are everywhere in modern code, so let's learn to read and write them.

- A shorter way
- An arrow: =>
- Everywhere in modern code
From long to short
Here's the same function three ways. A normal function. An arrow function stored in a const. And for a single expression, the shortest form, where the braces and the return keyword disappear. With exactly one parameter, you can even drop its brackets. Run it.
function doubleA(n) {
return n * 2;
}
const doubleB = (n) => {
return n * 2;
};
const doubleC = n => n * 2;
console.log(doubleA(5), doubleB(5), doubleC(5));
const add = (a, b) => a + b;
console.log(add(2, 3));10 10 10 5
When to use them
Arrow functions are perfect for short functions, especially when you pass a function to another function, which we'll do a lot with arrays. Regular functions are still fine for bigger, named pieces of work. There's one deeper difference, about the keyword this, which we'll meet with objects.
| key | value |
|---|---|
| (a, b) => a + b | returns automatically |
| x => x * 2 | one parameter |
| { return ... } | for several lines |
| Great for | short helpers |
Summary
Arrow functions are a short way to write functions. One expression returns automatically. Next, scope, where variables can be seen.
Key takeaways- const f = () => {}
- x => x * 2
- Short and common