What is () => in JavaScript ?
Last Updated :
31 Jan, 2024
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
const add = function (a, b) {
return a + b;
};
const addArrow = (a, b) => a + b;
console.log(add(3, 5));
console.log(addArrow(3, 5));
|
Share your thoughts in the comments
Please Login to comment...