Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of default parameters of JavaScript function

Shulou Source: shulou.com Published: 2022-06-01 04:24:49 09月27日 Update

This article mainly shows you the "example analysis of the default parameters of the JavaScript function", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and study the "example analysis of the default parameters of the JavaScript function".

Function default parameter

In JavaScript, a function argument (or formal parameter) is like a local variable of the function. When you call a function, you can pass or not pass a value. If you do not pass a value for the parameter, the value will be undefined and may cause some unnecessary side effects.

There is an easy way to pass default values to function parameters when defining parameters. In the following example, we pass the default value Hello to the parameter message of the greetings function.

Let greetings = (name, message='Hello,') = > {return `${message} ${name}`;} console.log (greetings ('Jack')); console.log (greetings (' Jack', 'Holaways')). This is all the content of the article "sample Analysis of default parameters of JavaScript function". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Functions parameters examples analysis content articles learning help side effects variables local methods easy to understand more organization knowledge editing industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker Microsoft Linux Shulou Tech Info