Concretely, this happened (node v12.22.9):
me@my-machine:~/Projects/.../my-projects$ node
Welcome to Node.js v12.22.9.
Type ".help" for more information.
> let foo = (function(){ throw new Error() })()
Uncaught Error
at REPL1:1:30
> foo
Uncaught ReferenceError: foo is not defined
> foo = 1
Uncaught ReferenceError: foo is not defined
> let foo = 1
Uncaught SyntaxError: Identifier 'foo' has already been declared
> let bar
undefined
> bar = (function(){ throw new Error() })()
Uncaught Error
at REPL6:1:26
> bar
undefined
> bar = 1
1
> let bar = 1
Uncaught SyntaxError: Identifier 'bar' has already been declared
If you see, I cannot:
- Retrieve the value of
foo
, since it is not defined. - Assign a new value to
foo
, since it is not defined. - Define it again (with or without initial value), since it is already defined.
This renders the identifier foo
completely unusable (until I close the console session). This, however, does not happen to bar
, since I don't initialize it to an expression throwing an exception (I assign bar
to an expression throwing an exception after the variable bar
is defined).
Is this a bug or an expected behaviour? is there a way I can clear this behaviour (without restarting the repl) and re-use foo
?