firefoxfirefox-developer-tools

How to reset Firefox console without refreshing the page?


How can I reset a Firefox Web Console in order to be able to use variables already declared?

console.clear() will only clear the output. All variables already declared are sticking in memory. I'm trying to get rid of:

Error: "SyntaxError: redeclaration of..."

Solution

  • When testing something, use the same construction you would (well, should) use to prevent code and variables being dropped in the global scope. Use Immediately Invoked Function Expressions (IIFE) and place your code in it. Each IIFE is it's own context, so re-declaring is not a problem.

    (function () {
      const myConstant = 1;
    
      console.log(myConstant);
    }());
    

    Note that Chrome 80 allows redeclaration of const and let. There exists a relevant bug in bugzilla for Firefox.