Default parameter
A default parameter is a function parameter assigned a specified value when its argument is omitted or, in JavaScript, undefined.
Secrets of the JavaScript Ninja, Second Edition
A function parameter with a default value used when the caller omits an argument or passes undefined.
- How it is used
- Provides a fallback for function arguments that callers often omit or leave unspecified.
- How deep it goes
- Explains parameter syntax and contrasts it with a manual undefined check, without exploring runtime internals.
- Examples
- Uses configurable slider settings and a ninja action that defaults to skulking but can be set to sneaking.
- What you can do after
- Apply ES6 default parameter syntax to define fallback values while allowing callers to pass alternatives.
Read how Secrets of the JavaScript Ninja, Second Edition explains default parameter →
Secrets of the JavaScript Ninja, Third Edition
A default parameter is a function parameter that receives a specified fallback value when the corresponding argument is omitted or undefined.
- How it is used
- Simplifies function APIs by supplying sensible fallback behavior when callers omit an argument.
- How deep it goes
- Explains assignment syntax, overrides, evaluation order, and references to earlier parameters; cautions against complex defaults.
- Examples
- Uses a ninja action default and an overridden action to demonstrate fallback behavior.
- What you can do after
- Apply JavaScript parameter syntax to provide fallbacks while allowing callers to override them.
Read how Secrets of the JavaScript Ninja, Third Edition explains default parameter →
JavaScript in Depth
A function parameter that receives a specified default expression value when the corresponding argument is omitted or undefined.
- How it is used
- Explains surprising name resolution and closure behavior when functions use default expressions.
- How deep it goes
- Descends to the intermediate parameter scope and its shadowing rules, rather than stopping at default-value syntax.
- Examples
- Uses outer and inner x bindings, chained defaults, and a closure that captures a shadowed parameter.
- What you can do after
- Evaluate/understand which binding a default expression or nested function captures in JavaScript.
Also covered in
- High Performance Unity Game DevelopmentIn early access (MEAP)
What to know first
- arrow functionAn arrow function is a JavaScript function expression written with arrow syntax that uses lexical binding for this and has no own arguments object.
- function argumentA function argument is a value or expression supplied when a function or method is invoked, providing input to the called operation.
- undefinedIn JavaScript, undefined is a primitive value that indicates a value is missing, unassigned, or unavailable.
- parameterA parameter is a value or named input that specifies or influences the behavior, computation, or output of a function, model, or system.
Related concepts
- parameterkind of · A parameter is a value or named input that specifies or influences the behavior, computation, or output of a function, model, or system.
- default valueuses · A default value is a predefined value automatically applied when no explicit value is supplied or specified.
- branchproduces · A branch is an alternative execution path selected according to a condition, outcome, or system state.
- function argumentuses · A function argument is a value or expression supplied when a function or method is invoked, providing input to the called operation.
Questions about default parameter
What is default parameter?
A default parameter is a function parameter assigned a specified value when its argument is omitted or, in JavaScript, undefined.
Which Manning books explain default parameter?
Secrets of the JavaScript Ninja, Second Edition, Secrets of the JavaScript Ninja, Third Edition and JavaScript in Depth.
What should I know before learning default parameter?
Manning books that teach default parameter usually introduce arrow function, function argument, undefined and parameter first.
What is default parameter a kind of?
Default parameter is a kind of parameter. A parameter is a value or named input that specifies or influences the behavior, computation, or output of a function, model, or system.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


