The arrow function syntax
Arrow functions are a shorter way to write functions. They were added in ES6 and are now the most common function syntax in modern JavaScript — especially in React.function keyword, add => after the parameters. That’s it.
Implicit return
When your function body is a single expression, you can skip the curly braces and thereturn keyword:
=> when there are no curly braces.
Single parameter shorthand
When an arrow function has exactly one parameter, you can drop the parentheses:Some teams require parentheses around all parameters for consistency. Either style is fine — Prettier will handle this for you based on your config.
Where you’ll use arrow functions
Arrow functions shine as callbacks — functions you pass to other functions. You’ll write these constantly:Arrow functions vs regular functions
For this course, here’s the practical rule:Arrow functions have a technical difference with
this binding, but you won’t encounter it in this course. React function components and hooks don’t rely on this, so it’s a non-issue. If you’re curious, MDN has a detailed explanation.Comparing to Python lambdas
- JavaScript
- Python
Common mistakes
Forgetting to return with curly braces
Forgetting to return with curly braces
Returning an object literal
Returning an object literal
What’s next?
You can write functions in both styles. Now let’s look at what goes inside the parentheses — parameters, default values, and destructuring.Parameters and arguments
Default values, rest parameters, and destructuring