JavaScript · Senior · Question 48 of 75

What is the Temporal Dead Zone for default parameters?

function f(a = b, b = 1) { return a; }
f();

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.

Further reading

Problem with a question

JavaScript · Senior · question 48

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz