MoreLesson 280Free preview
JS Default Parameters
This lesson is part of How To · All levels
Summary
The default parameter provides a backup value when the function argument is not given or is worth undefined. The default value is written directly into the list of parameters and evaluated whenever a function is called. Note that null does not trigger the default value, as null is considered an intentionally assigned value.
Key points
- Function sapa(nama = 'Tamu') use 'Guest' when the name undefined.
- The argument is not replaced by default; only the argument is triggered.
- Default can refer to previous parameters that have already been evaluated.
- The default value is evaluated at the time of the call, not when the function is defined.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.