What happens if you call a function with fewer arguments than parameters in JavaScript?
The missing parameters are set to undefined. You can handle this with default parameters, which apply only when the argument is undefined or omitted.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in undefined in Function Parameters and Returns in JavaScript
No. Defaults apply only when the argument is undefined or omitted. Passing null, 0, or empty string does not trigger the default, because those are real values.
undefined. If a function has no return, or a return with no expression, it returns undefined to the caller.
Check if the parameter === undefined, or use a default parameter. You can also check arguments.length (in regular functions) to see how many arguments were actually passed.
Still have questions?
Browse all our FAQs or reach out to our support team
