An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
April 25, 2021 10:14 pm GMT
Original Link: https://dev.to/rthefounding/setting-default-parameters-for-your-functions-29pa
Setting Default Parameters for Your Functions
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 6console.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.
Original Link: https://dev.to/rthefounding/setting-default-parameters-for-your-functions-29pa
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To