Default parameters allow you to set default values for function parameters if the function is called without arguments, or if the parameter is explicitly passed the value
undefined. However, in some cases it may be useful to set a different default value. This is where the default options are intended.
Passing other "false" values
If any value other than
undefined is passed to the formal parameter during the call, including one of the" false "values such as false ❎,
NaN, then in this case the default value will not be assigned to the parameter. In this case, you need to write the code yourself that will catch these "false values".
In the default parameters, you can use the values of the previous (located to the left in the list) parameters:
An example of a function with and without default parameters 👇:
The result will be the same, but without default parameters, the code📟 can become noticeably larger.
Write to Discord chat.
If no value is passed to function parameters⚙️, what is their default value?
Are the default parameters "catching" false values?
Is it possible to use the values of the parameters located to the left of the list in the default parameters?
In order to understand how much you learned this lesson, take the test in the mobile application of our school on this topic or in our telegram bot.
Thanks goes to these wonderful people (emoji key):
🐛 🎨 🖋
🖋 🐛 🎨