JavaScript · Senior · Question 48 of 75
What is the Temporal Dead Zone for default parameters?
function f(a = b, b = 1) { return a; }
f();- ✓Correct answer:
ReferenceError: parameterbisn't initialized yet whenais evaluated - 2Returns
1: default parameters are evaluated in any order - 3Returns
undefined:bis hoisted with the valueundefined
Explanation
Parameters are initialized left to right and behave like let: accessing a not-yet-initialized parameter is a TDZ error. In the reverse order (a = 1, b = a) it works. Default values are evaluated on every call, not once.