JavaScript `Arrow functions`

GEC Rajkot 2026.
In JavaScript, an arrow function is a more concise way to write functions, introduced in ES6 (ECMAScript 2015). Arrow functions offer a shorter syntax and behave differently from regular functions in terms of how they handle this binding, making them particularly useful in certain scenarios.
Syntax of Arrow Functions
Arrow functions are defined with a => symbol, also known as the "fat arrow." Here are some examples of how they work:
1.Basic Syntax:
const add = (a, b) => a + b;
Here,
addis an arrow function that takes two parameters,aandb, and returns their sum.When the function body contains only a single expression, you can omit the
{}braces and thereturnkeyword.
2.Single Parameter (No Parentheses):
If there’s only one parameter, you can omit the parentheses:
const square = x => x * x;
3.Multiple Statements (Braces Required):
If the function body has multiple statements, use {} and include return explicitly:
const addAndLog = (a, b) => {
const sum = a + b;
console.log(sum);
return sum;
};
4.No Parameters:
If there are no parameters, use empty parentheses:
const greet = () => "Hello, world!";





