Arrow functions enable a more concise syntax for writing functions.
Before:
hello |
With Arrow Function:
hello
|
It gets even shorter! If the function has a single statement that returns a value, you can omit both the curly braces and the return keyword.
Arrow functions return a value by default.
hello = () => “Hello World!”; |
Note: This applies only if the function contains a single statement. |
If you have parameters, include them within the parentheses.
Arrow Function with Parameters
hello = (val) => “Hello “ + val; |
In fact, if you have just one parameter, you can also omit the parentheses.
Arrow Function Without Parentheses
hello |