Arrow Functions in JavaScript: A Simpler Way to Write Functions

How arrow functions cut the boilerplate
Writing a small function to double a number in traditional JavaScript looks like this:
function double(num) {
return num * 2;
}Four lines of ceremony for one simple idea: “take a number, double it.” Arrow functions, introduced in ES6, let you write the exact same logic far more compactly:
const double = num => num * 2;Same behavior, one line, no function keyword, no return keyword, no curly braces. This guide walks through arrow function syntax step by step, converting familiar examples along the way.
What Arrow Functions Are
An arrow function is a shorter syntax for writing a function in JavaScript, using => (an "arrow") instead of the function keyword.
// Regular function
function greet(name) {
return "Hello, " + name;
}
// Arrow function — same behavior
const greet = (name) => {
return "Hello, " + name;
};Both versions do exactly the same thing when called — greet("Aarav") returns "Hello, Aarav" either way. Arrow functions don't add new capability; they add a cleaner, more compact way to express the same idea.

Basic Arrow Function Syntax
The general shape of an arrow function:
const functionName = (parameters) => {
// function body
return someValue;
};Breaking this down piece by piece:
const functionName =— stores the function in a variable, just like any other value(parameters)— the input values the function accepts, same as a regular function=>— the arrow, replacing thefunctionkeyword{ ... }— the function body, containing the actual logic

Arrow Functions With One Parameter
When a function takes exactly one parameter, the parentheses around it become optional:
const square = (num) => {
return num * num;
};
// Parentheses are optional with a single parameter:
const square = num => {
return num * num;
};Both versions behave identically — dropping the parentheses is simply a style choice many developers use for extra brevity when there’s only one parameter.
Arrow Functions With Multiple Parameters
When a function takes more than one parameter, the parentheses become required:
const add = (a, b) => {
return a + b;
};
add(3, 4); // 7// This would be a syntax error — parentheses can't be dropped with multiple parameters:
const add = a, b => { return a + b; }; // invalid syntaxA simple rule to remember: zero or one parameter → parentheses are optional; two or more → parentheses are required.
// Zero parameters — parentheses are required here too
const sayHello = () => {
return "Hello!";
};

