How do we know let is hoisted if accessing it early throws?
Because an inner let with the same name as an outer variable shadows the outer from the start of the block. If it were not hoisted, the outer would be found. The fact that it throws proves the inner let is hoisted and in the TDZ.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in How let and const Are Hoisted in JavaScript
Yes, memory is allocated for them during the memory allocation phase. But unlike var, they are not initialized to undefined. They sit in the Temporal Dead Zone until the declaration line, and accessing them early throws ReferenceError.
var is hoisted AND initialized to undefined, so it is usable early (returns undefined). let and const are hoisted (memory allocated) but NOT initialized, so they sit in the TDZ and throw ReferenceError if accessed early.
Yes, but like let and const, they are hoisted without initialization. They sit in the TDZ until the declaration line. Accessing a class before its line throws ReferenceError.
Still have questions?
Browse all our FAQs or reach out to our support team
