Skip to main content
Default parameters allow JavaScript function parameters to be initialized with default values if undefined is passed or if no argument is provided during the function invocation.

Evaluation Mechanics

Strict undefined Trigger The default value is applied strictly when the argument is omitted or explicitly passed as undefined. Other falsy values, such as null, 0, false, or "" (empty string), are considered valid arguments and will bypass the default parameter assignment.
Call-Time Evaluation Unlike some languages where default parameters are evaluated at parse time, JavaScript evaluates default parameters at call time (execution time). If the default value is a reference type (like an Array or Object), a new instance is allocated in memory for every function invocation that triggers the default.
Parameter Scope and Left-to-Right Evaluation Parameters defined in the function signature form their own scope, which sits between the outer scope and the function body’s inner scope. Default parameters are evaluated sequentially from left to right. Because of this left-to-right evaluation, a default parameter can reference preceding parameters. However, attempting to reference a parameter that appears later in the signature results in a ReferenceError due to the Temporal Dead Zone (TDZ).
Function Calls as Default Values Because defaults are evaluated at call time, you can assign the return value of a function execution as a default parameter. The assigned function will only execute if the default parameter is triggered.

Interaction with Destructuring

Default parameters are frequently combined with object or array destructuring to provide fallback values for nested properties, as well as a fallback for the destructured object itself.
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More