EN VI

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

2024-03-09 23:00:23
Javascript - "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-->

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".

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login