- Function as statement
- Function as expression
A function statement can be created as shown below:
The same function can be created as a function expression as shown below:
ECMA 2015 (or ECMA Script 6) introduced shorter syntax to write a function expression called the arrow function. Using the arrow function, you can write the function expression above as seen here:
As you see, writing a function expression using the arrow function is shorter.
Basic syntax rules for arrow functions
First, parameters should be passed in the small parentheses. You can create an arrow function with two parameters as shown below: