The following code produces an error when I run it in Firefox 52 Scratchpad:
function scope() {
let x = 1;
}
let x = 2;
/*
Exception: SyntaxError: redeclaration of let x
@Scratchpad/8:1:1
*/
How to explain that? The first x
should be encapsulated in the function and not interfere with the second declaration.
Running this code as a snippet in Chrome, or inside an HTML page with a <script>
tag in Firefox doesn't trigger the exception. Also wrapping it in a function, or even a pair of {}
brackets eliminates the problem.
Could it be a bug in Scratchpad?
It works if you only run it one time. The second time you try the same code, the original let x = 2;
is still alive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With