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
function add(a, b) {
return a + b;
}
Arrow function syntax
const 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.
Exercises
Use an Arrow Function for Addition
- Create an arrow function named add that takes two parameters and returns their sum.
- Call add with the numbers 3 and 4 and print the result using console.log.
Convert a Named Function to an Arrow Function
Given the following traditional function, rewrite it as an arrow function:
function square(n) {
return n * n;
}
- Assign the arrow function to a constant named square.
- Call square with the value 5 and print the result using console.log.


Ready to become an ethical hacker?
Start today.
As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.