Facebook Pixel

What is the difference between a const without an initializer and const reassignment in JavaScript?

const x; (no initializer) is a SyntaxError caught at parse time. const x = 5; x = 10; (reassignment) is a TypeError thrown at runtime. Different error types because they fail at different stages.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in TDZ Interview Questions for let and const in JavaScript

ReferenceError: Cannot access 'x' before initialization. The message is specific to the TDZ, different from 'x is not defined' which means the variable does not exist at all.

No. typeof on a let or const in the TDZ throws ReferenceError. This is different from typeof on an undeclared variable, which returns 'undefined' without throwing.

Because the inner let is hoisted (memory allocated) at the start of the block, so it shadows the outer immediately. But it is in the TDZ until its declaration line, so accessing it early throws instead of falling back to the outer.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.