This content originally appeared on DEV Community and was authored by Randy Rivera
In order to help us create more flexible functions, ES6 introduces default parameters for functions.
- Ex:
const increment = (number, value = 1) => number + value;
console.log(increment(5)); will display 6
console.log(increment(5, 2)); will display 7
As you can see in the example above, we added a default parameter so that it will add 1 to number if value is not specified.
This content originally appeared on DEV Community and was authored by Randy Rivera

Randy Rivera | Sciencx (2021-04-25T22:14:57+00:00) Setting Default Parameters for Your Functions. Retrieved from https://www.scien.cx/2021/04/25/setting-default-parameters-for-your-functions/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.