Default Parameters
What will be logged? function test(a = 1, b) { return [a, b]; } console.log(test(undefined, 5));
The code will log `[1, 5]`. When the function is called with `test(undefined, 5)`, `undefined` is explicitly passed for parameter `a`, which has a default value of 1. Since `undefined` triggers the use of default parameters, `a` becomes 1. The second argument 5 is assigned to parameter `b`. Contrary to what some might expect, it is perfectly valid in JavaScript to have parameters without defaults following parameters with defaults. There is no syntax or runtime error for this. However, it's generally considered a good practice to position parameters with default values after parameters without defaults to improve readability, since required parameters conceptually come before optional ones. But the JavaScript language itself does not enforce this convention, and the function works correctly regardless of parameter order.