JS Console - variable redeclaration error

I have a problem with the JS console. A simple example:

I declare the variable k, assign a value to it, display it in the console with console.log, everything works as it should. But I need to change the k value to another one. I change, press the Run button and the error is displayed:

“SyntaxError: redeclaration of let k - debugger eval code:1”

To get around this, I have to copy the whole code (otherwise it will be deleted), refresh the page and paste the code back, and then k works with the new value. I think this works badly. Is this a bug?

Hello @MironF,

this is not a bug per-se.
It’s like you were writing a script like:

let k = 1;
let k = 2;

And this would throw in a script.
We have https://bugzilla.mozilla.org/show_bug.cgi?id=1580891 to work ardound this.

For now, you can use var instead of let, or try to wrap your expression in a block:

  let k = 1;

this would allow you to re-declare k in the console, but won’t make it available for future usage.

Hope this helps.

Note that the console preserves your command history, so you should not need to copy your snippets manually.

If you are using the Console in “multiline” mode, you can restore your previous snippets using the “up” and “down” arrows on the top right of the multiline panel. If you are using the regular Console (single-line) then you can navigate your history by pressing the “up” and “down” keys on your keyboard.