Arrow Functions in JavaScript: A Simpler Way to Write Functions
Master the modern, clean syntax of JavaScript Arrow Functions and learn how to write less boilerplate code

In our previous guide of the JavaScript Decoded series, we unlocked the powerhouse of JavaScript: Functions. We learned how to organize our logic using both Function Declarations and Function Expressions.
But what if I told you there was an even faster, cleaner, and more modern way to write functions?
Welcome to the world of Arrow Functions (=>).
Introduced in ES6 (a major JavaScript update in 2015), arrow functions changed the way developers write code. They allow us to strip away the boilerplate and write functions that are short, readable, and elegant.
In this guide, you will learn:
What arrow functions are and why developers love them
The basic syntax for writing them
How to handle zero, one, or multiple parameters
The magic of "Implicit Return" vs "Explicit Return"
The basic differences between arrow functions and normal functions
Let's clean up our code! 🚀
What Are Arrow Functions?
At their core, Arrow Functions are just a shorter syntax for writing Function Expressions.
They don't replace traditional functions entirely, but they act as a fantastic shortcut for writing small, concise logic. Think of them as the "shorthand" version of a function.
The Problem: Too Much Boilerplate
When writing a traditional function expression, you have to type the word function, the curly braces {}, and the return keyword.
If your function only does one simple thing, that feels like a lot of extra typing:
// The old, long way (Function Expression)
const sayHi = function(name) {
return "Hi, " + name;
};
Watch what happens when we convert this exact same logic into an arrow function:
// The modern, clean way (Arrow Function)
const sayHi = (name) => "Hi, " + name;
Boom! We shrunk three lines of code into a single, highly readable line. Let's break down how we got there.
Arrow Function Syntax Breakdown
Creating an arrow function is like taking a normal function and aggressively trimming the fat.
Here is what happens during the transformation:
Remove the
functionkeyword completely.Add a "fat arrow"
=>just after the parentheses().
Basic Syntax:
const addNumbers = (a, b) => {
return a + b;
};
console.log(addNumbers(5, 10)); // Output: 15
This is the standard syntax for an arrow function with multiple lines of code inside the body. It works exactly like the functions you already know!
Dealing with Parameters
Arrow functions are so flexible that their syntax actually changes slightly depending on how many parameters (arguments) you are passing in.
1. Multiple Parameters (Requires Parentheses)
If your function takes two or more parameters, you must wrap them in parentheses ().
const subtract = (x, y) => {
return x - y;
};
2. Exactly One Parameter (Parentheses are Optional!)
If your function only requires a single parameter, JavaScript lets you drop the parentheses altogether to make the code even cleaner.
// With parentheses (totally fine)
const double = (num) => {
return num * 2;
};
// Without parentheses (cleaner and preferred by many developers)
const doubleCleaner = num => {
return num * 2;
};
3. Zero Parameters (Requires Empty Parentheses)
If your function doesn't take any parameters at all, you must use an empty set of parentheses () to let JavaScript know it's a function.
const greetWorld = () => {
console.log("Hello, World!");
};
Implicit Return vs. Explicit Return
This is where Arrow Functions truly shine.
In a normal function, if you want to output a value, you must use the return keyword explicitly. Arrow functions, however, can return values automatically under the right conditions. This is called an Implicit Return.
Explicit Return (The standard way)
If your arrow function uses curly braces {}, you must use the return keyword. This is an explicit return. Use this if your function spans multiple lines of logic.
const multiply = (x, y) => {
const result = x * y;
return result; // We MUST use 'return' because of the { }
};
Implicit Return (The secret superpower)
If your function contains only one single expression (one line of logic that evaluates to a value), you can:
Delete the curly braces
{}Delete the
returnkeyword
JavaScript will implicitly assume that whatever is on the right side of the arrow => is what you want to return.
// No curly braces, no 'return' keyword!
const multiplyShorthand = (x, y) => x * y;
console.log(multiplyShorthand(3, 4)); // Output: 12
💡 Rule of Thumb:
If you use curly braces
{}, you need to writereturn.If you omit the curly braces, the return happens automatically!
Arrow Functions vs Normal Functions
Since Arrow Functions look so great, should you stop using normal functions entirely? No! While they are fantastic, they are not 100% identical to normal functions under the hood.
Here are the basic differences you should know as a beginner:
Syntax: Arrow functions are shorter and omit the
functionkeyword.Hoisting: Because Arrow Functions are stored in variables (like
const), they are not hoisted. You must define them before you call them down the page. (Normal Function Declarations are hoisted).The
thisKeyword: Normal functions behave differently depending on how they are called. Arrow functions are much simpler—they inherit their context from the surrounding code. (Don't worry if this sounds confusing right now; we will dedicate an entire future blog post exclusively to thethiskeyword!)
Why Developers Love Arrow Functions
You will see Arrow Functions everywhere in modern JavaScript, especially when working with Arrays. Because they are so short, they are perfect for passing quick, one-off logic into other functions.
(Sneak peek of what we will cover in the upcoming Arrays post!)
const names = ["Debesh", "Ankit", "Priya"];
// Look how clean this is! No 'function' or 'return' needed.
const excitedNames = names.map(name => name + "!");
console.log(excitedNames);
// Output: ["Debesh!", "Ankit!", "Priya!"]
Your Turn: Assignment Time! 💻
Ready to practice? Open your code editor and try solving these challenges:
Write a normal function expression named
calculateSquarethat takes a number, multiplies it by itself, and returns the result.Rewrite that exact same function into an Arrow Function with an Implicit Return (no curly braces or return keyword).
Create an Arrow Function called
isEventhat takes a numbern. If the number is even, returntrue. If it's odd, returnfalse. (Hint: use the modulo operator%!)Extra Credit: Create an array of numbers
[1, 2, 3, 4]. Use the.map()method along with an arrow function to double every number in the array.
What's Next?
Now that you've mastered both traditional functions and arrow functions, you have the tools needed to write clean, reusable logic. Next up, we will tackle repeating actions!
Loops and Iteration —
for,while, and executing logic repeatedlyArrays — Storing lists of data
Array Methods —
map,filter, andreduce
Happy coding! 🎉





