Skip to main content

Command Palette

Search for a command to run...

JavaScript `Arrow functions`

Published
1 min readView as Markdown
JavaScript `Arrow functions`
P

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, add is an arrow function that takes two parameters, a and b, and returns their sum.

  • When the function body contains only a single expression, you can omit the {} braces and the return keyword.

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!";
M

Great post. Concise and clear to understand

1
P

Thanks :)