TDZ là khoảng thời gian từ khi block bắt đầu đến khi biến let/const được khai báo. Trong TDZ, việc truy cập biến sẽ ném ReferenceError dù biến đã được hoisted.
Ví dụ: console.log(x); let x = 5; sẽ throw ReferenceError, trong khi var chỉ trả về undefined. TDZ giúp phát hiện lỗi dùng biến trước khi khai báo — điều var cho phép nhưng gây bug khó tìm. Khi phỏng vấn hỏi về TDZ, nhớ nêu rằng biến vẫn được hoisted nhưng chưa được khởi tạo.
The TDZ is the period from when a block begins until a let/const variable is declared. Accessing the variable in the TDZ throws a ReferenceError even though it has been hoisted.
Example: console.log(x); let x = 5; throws ReferenceError, while var only returns undefined. TDZ helps catch bugs where a variable is used before being declared — something var allows but which causes hard-to-find bugs. When asked about TDZ in interviews, remember to note the variable is still hoisted but not yet initialized.