What is () => in JavaScript ?
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
Contact Us