AJP AJP - 5 months ago 28
Javascript Question

Possible to enable "strict mode"; in FireBug and Chrome's console?

With this page:

<!DOCTYPE html>
"use strict";
var foo = 2;
delete foo;

Firebug console gives:

applying the 'delete' operator to an unqualified name is deprecated
>>> foo
ReferenceError: foo is not defined

But then this is successful:

>>> var bar = 2;
>>> delete bar;

Even if you comment out
delete foo;
so that the script does not break, deleting
is still successful despite the fact it "is a property of a Global object as it is created via variable declaration and so has DontDelete attribute":

>>> foo
>>> delete foo
>>> var bar = 2;
>>> delete bar

Is it possible to enable "strict mode"; in FireBug and or Chrome's console?


The firebug console works by wrapping all the code in an "eval" call so the first statement in your script is no longer "use strict" - hence it is disabled. You could try wrapping your code in a function to enforce "use strict" for that particular function but the best solution I know of is to skip the console and test straight in the page itself.