16JavaScript
Arrow Functions in JavaScript
Easy20MIN
What Are Arrow Functions?
Arrow functions are a modern, concise way to write functions in JavaScript. Instead of using the traditional function keyword, arrow functions use the** =>** syntax. They often make your code shorter and easier to read.
For example, consider a simple function that adds two numbers:
Traditional function syntax
JAVASCRIPT
1function add(a, b) {
2 return a + b;
3}Arrow function syntax
JAVASCRIPT
1const add = (a, b) => a + b;In the arrow function version:
- We use const to declare add (since its definition won’t change).
- The parameters are listed in parentheses, followed by an arrow =>.
- If the function consists of a single expression, that expression is automatically returned.
1 / 3
Hakatemia Pro
Learn to hack — start here
Hundreds of interactive courses, virtual labs and CTF challenges in your browser. Start a free trial — no card required.