How to return value from an arrow function in JavaScript?
How to return value from an arrow function in JavaScript?
193
08-Oct-2023
Updated on 09-Oct-2023
Aryan Kumar
09-Oct-2023In JavaScript, you can return a value from an arrow function just like you would with a regular function. Arrow functions allow you to create concise one-liners for returning a value. Here's how you can return a value from an arrow function:
Arrow functions are especially useful for short, single-expression functions, as they allow you to omit the curly braces {} and write the expression directly after the =>, making the code more concise. For such functions, you can return a value without using the return keyword explicitly, like this:
This is known as an implicit return, and it works when the function body consists of a single expression.