Welcome Guest! (App Version 3.1)
Another new features in ES6 (EcmaScript 2015) is
Default Parameters. This means that if the number of parameters that a function asks are satisfied then its fine, but if the number of parameters falls less than those in the arguments of function, then you got an option of setting some default values for them.
Look at the following examples:
alpha = (a=10, b=5, c=2) => a * b -c; alpha(13, 5, 3); //result is 62 alpha(8,3); //result is 22 alpha(7); // result is 33 alpha(9,,8); //Error: Unexpected token ,
Explaination: In first case when you are passing (13, 5, 3) then no default values will be picked in function as all values are passing so (13 * 5 -3) = 62. In second case you are passing first 2 values but third is not passed, so it will be picked as default. So final result is (8 * 3 -2 = 22). In third case, since only first value is passed so 2nd and 3rd values in arguments will be picked by default values. So, result is (7 * 5 -2 = 33). Also, you cannot skip values while passing to function parameters, so final function call will throw error.