Arrow Functions in JavaScript: A Simpler Way to Write Functions

Arrow Functions in JavaScript: A Simpler Way to Write Functions
Let’s be honest about something.
Developers love doing more work with less code. If there’s a shorter way to write something, we’ll take it every time.
That’s exactly why arrow functions exist in JavaScript.
They allow you to write functions in a shorter, cleaner, and more readable way—especially when working with modern JavaScript features like arrays and callbacks.
In this article, we’ll break down arrow functions from basic to practical usage, so even beginners can understand them clearly.
1. What Exactly Are Arrow Functions?
Arrow functions are a shorter syntax for writing functions in JavaScript.
Before arrow functions were introduced in ES6, writing functions required the function keyword and more boilerplate code.
Example of a normal function:
function multiply(a, b) {
return a * b;
}
Now the same function written using an arrow function:
const multiply = (a, b) => {
return a * b;
};
What changed?
Three main things:
The
functionkeyword is removedA fat arrow
=>is usedThe function is usually stored inside a variable
Arrow functions make the code more concise and easier to read.
2. Simplifying the Function Even Further
If the function only returns a single value, we can simplify it even more.
Example:
const multiply = (a, b) => a * b;
Here we removed:
curly braces
{ }the
returnkeyword
JavaScript automatically returns the result.
This is called implicit return.
3. Arrow Function with One Parameter
When an arrow function has only one parameter, the parentheses can be removed.
Example:
Normal version:
const greet = (name) => {
return "Hello " + name;
};
Simplified version:
const greet = name => {
return "Hello " + name;
};
Both versions work the same way.
Developers often prefer the second version because it looks cleaner.
4. Implicit Return (The Real Power)
Arrow functions become very powerful when used with one-line expressions.
Example: Squaring a number.
Normal version:
const square = (n) => {
return n * n;
};
Short version using implicit return:
const square = n => n * n;
Important rule:
If you use
{ }→ you must writereturnIf you remove
{ }→ JavaScript automatically returns the value
5. Arrow Functions vs Normal Functions
| Feature | Normal Function | Arrow Function |
|---|---|---|
| Syntax | Longer | Short and concise |
this behavior |
Has its own this |
Uses this from surrounding scope |
| Hoisting | Can be called before definition | Must be defined first |
| Best Use | Complex logic | Small functions and callbacks |
One important difference is how this behaves.
Arrow functions do not create their own this.
They inherit this from the surrounding code.
This behavior makes them very useful inside callbacks.
6. Real-World Example: Even or Odd Checker
Here is a simple program that checks if a number is even or odd.
const checkEvenOdd = num => num % 2 === 0 ? "Even Number" : "Odd Number";
console.log(checkEvenOdd(10));
console.log(checkEvenOdd(7));
Explanation:
%gives the remainderIf remainder is
0→ number is evenOtherwise → number is odd
7. Arrow Functions with Array Methods
In modern JavaScript development, arrow functions are commonly used with array methods.
Example using map().
const prices = [100, 200, 300, 400];
const discountedPrices = prices.map(price => price * 0.9);
console.log(discountedPrices);
Output:
[90, 180, 270, 360]
What happened here?
map()loops through the arrayEach price gets multiplied by
0.9A new array is returned with discounted values
Arrow functions make this code clean and easy to read.
8. When Should You Use Arrow Functions?
Arrow functions are best used when:
Writing short functions
Working with array methods like
map,filter, andreduceWriting callbacks
Keeping code concise
However, they are not ideal for every situation, especially when dealing with objects that rely heavily on this.
9. Summary
Arrow functions provide a modern and cleaner way to write functions in JavaScript.
Key takeaways:
No
functionkeyword neededUse
=>between parameters and function bodyOne parameter → parentheses optional
One line → implicit return possible
Great for callbacks and array methods
Mastering arrow functions is an important st




