Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"Uncaught ReferenceError: a is not defined" instead of "ReferenceError: Cannot access 'a' before initialization"

In this simple code, since the variable b is a let variable and i am trying to log() its value, I was expecting a reference error that said: cannot access ‘a’ before initialization,

but instead i am getting the error:
Uncaught ReferenceError: a is not defined

console.log(a);
let a=10;
var b=19;

a screenshot of the code and the error–>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i ran the same code in online js editors and they give the expected error, i am confused now :
the same code on an online editor with different error

>Solution :

According to error docs it happens within any block statement

Since you don’t have block statement, JS fires another error.

enter image description here

I suppose that in online editor, the code is executed by another code, so there could be block statement outside the "file".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading