Facebook Pixel

Is the illegal shadowing error a SyntaxError or a ReferenceError in JavaScript?

SyntaxError. The engine catches the duplicate declaration at parse time, before any code runs. The message is 'Identifier x has already been declared.'

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Illegal Shadowing in JavaScript Explained

You cannot shadow a let, const, or class with a var in the same scope. var is function-scoped and leaks out of blocks, so it would conflict with the outer let/const/class. The engine throws SyntaxError: Identifier has already been declared.

Yes. Shadowing a var with a let is legal because let is block-scoped and does not leak out. There is no conflict. The reverse (shadowing a let with a var) is illegal.

Because var ignores block boundaries and would leak into the scope where the let is declared, creating two declarations of the same name in the same scope. The engine catches this at parse time.

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.