Skip to main content

Default parameters

@serverSerrverlesskiy

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.

Teacher

In JavaScript, function parametersβš™οΈ that are not passed values when called are defaulted to undefined. However, in some cases it may be useful to set a different default value. This is where the default options are intended.

Syntax#

book

Live Editor
Result
SyntaxError: Unexpected token (1:8)
1 : return ()
            ^

Passing other "false" values#

basketball

If any value other than undefined is passed to the formal parameter during the call, including one of the" false "values such as false ❎, 0, " ", '', null,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".

Payment#

Now you are on a stripped-down version of the site, after subscribing to Patreon, you will get full access to the training course, as well as access to our server's private channels in Discord.

Download our mobile application or get tested in our JavaScript telegram bot, and also subscribe to our news.

Become a Patron!

Sumerian school

Links#

  1. MDN web docs

Contributors ✨#

Thanks goes to these wonderful people (emoji key):


Philipp Dvinyaninov

πŸ“–

Dmitriy Vasilev

πŸ’΅

Resoner2005

πŸ› 🎨 πŸ–‹

Navernoss

πŸ–‹ πŸ› 🎨

Become a Patron!