Functions in ES6
Functions
In ES6, we can put the default values right in the signature of the functions. Default value expressions are evaluated at function call time from left to right.
The new syntax is quite handy when you just need a simple function with one argument. You can skip typing function and return, as well as some parentheses and braces.
Syntax:-
const hello = x => "Hi! " +x;
Explanation:-
The code above defines a function named hello that has one argument and returns a message.
Similarly, we can add multiple parameters.
Example 1:-
const add = (x,y) => x+y;
Example 2:-
We can define the default value of the parameter like this:-
const div = (x,y=2) => x/y;