Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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..."
like image 961
taha Avatar asked May 13 '17 12:05

taha


2 Answers

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.

like image 113
Sumurai8 Avatar answered Oct 07 '22 01:10

Sumurai8


if refreshing the page will reset the console, then you can use location.reload() to refresh the page via console.

like image 24
Fatemeh Karimi Avatar answered Oct 06 '22 23:10

Fatemeh Karimi