Default Parameters

Default Parameters:

If you are familiar with other programming languages like Ruby, Python then default parameters isn’t new to you.

Default parameters are parameters which are given by default while declaring a function. But it’s value can be changed when calling the function.

Example

let Func = (a, b = 10) => {
 return a + b; 
}
Func(20); // 20 + 10 = 30

In the above example, we are passing only one parameter. The function makes use of the default parameter and executes the function.

Consider another example:

Func(20, 50); // 20 + 50 = 70

In the above example, the function takes two parameters and the second parameter replaces the default parameter.

来源:https://codeburst.io/es6-tutorial-for-beginners-5f3c4e7960be