Default Parameters
What is the key advantage of using default parameters over the old pattern of checking arguments inside the function body?
The key advantage of using default parameters is that they provide clear, self-documenting function signatures. With default parameters, anyone reading the function declaration can immediately see what parameters are optional and what their default values are, without having to examine the function body. This improves code readability and maintainability. In contrast, the old pattern of checking arguments inside the function body (e.g., `x = x || defaultValue;`) obscures the function's interface by mixing parameter handling with business logic. Additionally, default parameters handle edge cases better, particularly with falsy values. The old OR (`||`) pattern would incorrectly apply defaults for valid falsy inputs like 0 or empty strings, whereas default parameters only activate when the value is actually missing (`undefined`). Default parameters also reduce boilerplate code, resulting in cleaner, more concise functions, and they better support type-checking and IDE hints in modern development environments.