1

Sometimes when I am working with the chrome dev tools - and I use let statement to declare some variables:

let x = 1;
x++;
console.log(x);
let x = 2;

The last line will throw an Uncaught SyntaxError: Identifier 'x' has already been declared.

How can I clear the current scope (or all the variables I created from all the older statements) - so that if I declare them again - it's a fresh start and they get all garbage collected or just disposed.

I don't want to open a new tab since I am using a full-window chrome dev tools window like this

enter image description here

braX
  • 11,506
  • 5
  • 20
  • 33
Probosckie
  • 1,585
  • 4
  • 25
  • 40
  • 1
    I don't think you can. You can hit F5 to reload the (parent) page but it's probably not a good solution for a lot of situations. – VLAZ Aug 27 '19 at 10:26
  • 1
    You can't, afaik, because the dev tools console share the same environment as your opened page, and you just can't yeet variables into complete non-existence so you can reuse `let` and `const` on them again. You either reload, reassign or just use a different variable. We have infinite possible variable names to use for quick testing – Abana Clara Aug 27 '19 at 10:28
  • @AbanaClara I personally completely omit variable declarations, so it's just `x = 1` or use `var`. it works for code that it going in the console, and if I need to turn it into a production code, I'll just transcribe it appropriately. – VLAZ Aug 27 '19 at 10:33

0 Answers0