Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 25, 2021 10:14 pm GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To