I know let in JS cannot be declared the variable twice. But when I try the below code in my console:
a = 1;
let a = 2;
let a = 3;
.
.
.
let a = 100;
Note: They are run line by line (as shown in the screenshot below). The version is Google Chrome 91.0.4472.114
It always works, no error. This really confuses me, why it works fine? I know what happens in the console isn't indicative of what happens in a script. But my question is why this exists in console? Is there any reason for that, or it might be a bug?
Because I suppose that let and const have the same declaration behavior, if I use const instead of let, there is no doubt about it.
b = 1;
const b = 2;
const b = 3; //Uncaught SyntaxError: Identifier 'b' has already been declared