Open In App

What is () => in JavaScript ?

Last Updated : 31 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In JavaScript, () => is the syntax used to declare an arrow function. Arrow functions provide a concise and more readable way to write function expressions. The () => syntax is used to define a function without the need for the function keyword.

Example: Here, add and addArrow are equivalent functions that take two parameters (a and b) and return their sum.

Javascript




// Regular function expression
const add = function (a, b) {
  return a + b;
};
 
// Arrow function equivalent
const addArrow = (a, b) => a + b;
 
console.log(add(3, 5));      // Output: 8
console.log(addArrow(3, 5)); // Output: 8


Output

8
8

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads