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

Viewed 6390

With this page:

<!DOCTYPE html>
<html>
  <head>
    <script>
        "use strict";
        var foo = 2;
        delete foo;
    </script>
  </head>
  <body></body>
</html>

Firebug console gives:

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

But then this is successful:

>>> var bar = 2;
undefined
>>> delete bar;
true

Even if you comment out delete foo; so that the script does not break, deleting bar 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
2
>>> delete foo
false
>>> var bar = 2;
undefined
>>> delete bar
true

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

5 Answers

use shift+enter to input 'use strict'

like this enter image description here

Chrome: put 'use strict'; prefix in your code line (and/or shift+enter for multiline)

'use strict'; var foo = 2; delete foo;

On Chrome go to "chrome://flags", then "Enable Experimental JavaScript". Relaunch.

Related