Default Parameters
What will be logged? const b = 2; function test(a = b, b = 3) { console.log(a, b); } test();
This code will throw a `ReferenceError: Cannot access 'b' before initialization`. The error occurs because default parameter expressions create their own scope, and parameters are initialized from left to right. When evaluating the default value for parameter `a`, the expression refers to `b`. However, at this point in the parameter list, the parameter `b` exists but hasn't been initialized yet—it's in the Temporal Dead Zone (TDZ). The `b` referenced in `a = b` refers to the parameter `b`, not the global `b` variable with value 2, because the parameter shadows the global variable in this scope. This example demonstrates the TDZ for default parameters—you can reference parameters that appear earlier in the list (to the left), but not those that appear later (to the right), as they're not yet initialized. To fix this issue, you could either reorder the parameters, use a different name for one of the variables, or explicitly pass a value for parameter `a` to avoid using its default value.