I've been playing around with JavaScript to learn some concepts, and stumbled across this small example.
Consider the function:
function foo() {
console.log(x);
}
and then, run:
> foo(); let x = 10;
I get the expected:
ReferenceError: x is not defined
at foo (repl:2:13)
But, surprisingly, I neither cannot define x
> let x = 10;
SyntaxError: Identifier 'x' has already been declared
nor reassign it
> x = 10;
ReferenceError: x is not defined
Is this behavior expected? What's the state of x
?
Edit:
Example on Google Chrome: