JavaScript
/Beginner
Default Parameters
Definition
Allows named parameters to be initialized with default values if no value or `undefined` is passed to the function.
Explain Like I'm New
It's a fallback safety net. If you ask a user for their preferred theme, and they don't answer, you automatically set it to 'light' instead of breaking the app with 'undefined'.
Real World Example
Setting a default configuration object: `function initialize(config = { retries: 3 }) { ... }`
Common Use Cases
- •Simplifying function signatures
- •Avoiding `||` short-circuit hacks inside functions
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- How do you assign a default parameter?
intermediate
- If you pass `null` as an argument, does the default parameter trigger?
advanced
- Can a default parameter reference a previous parameter?