15JavaScript
Named vs. Anonymous Functions
Easy25MIN
What Is a Named Function?
A named function is a function that has its own identifier. You define it separately and can refer to it by name whenever needed. For example:
JAVASCRIPT
1function isEven(num) {
2 return num % 2 === 0;
3}
4
5let numbers = [3, 7, 8, 11];
6let firstEven = numbers.find(isEven);
7console.log(firstEven); // prints 8Here, the function isEven is defined once and then passed as an argument to the find() method. This is clear and helps organize your code if you use the same function in multiple places.
1 / 5
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.