When ES6 (ECMAScript 2015 or ECMAScript 6) came into the role, It was a major revision in javaScript and introduces new syntax.
One of these syntaxes was Arrow Function. Arrow function syntax introduces new ways to write a function, The way made code less and easy to write and readable too, we don't need to write function and return keywords for a single expression.
Without using Arrow function
Using Arrow function
Now let's see what's happens with a single line of code in Arrow Function.
So, The differences in the Arrow function are?
- There are no parentheses with parameters.
- There are no curly braces for the function body.
- The syntax is easy to write and read.
- return keyword is not required for a single expression.
Syntax for Arrow Function
Arrow function for single parameter and a single return statement
For more than one parameter with a single return statement
For multiple statements
Some importants points
- No parentheses require for a single parameter
- no return keyword require or a single expression
- return keyword require for multiple expression
- parentheses require for multiple parameters.