General Restrictions

Strict Mode can be applied to an entire script by placing "use strict"; before any other statements in the script. Strict state is not shared across different scripts.

Strict Mode enforces the following:

Global variables cannot be declared without using a declaration keyword.


"use strict";
a = 10;

Reference Error

Non-writable properties cannot be deleted.


"use strict";
// delete Object.prototype; // TypeError
delete window.undefined;

TypeError

Octal syntax is not supported.


"use strict";
var x = 0777;

Syntax Error

The keyword 'with' is not supported.


"use strict";
var o = { a: 3 };
with (o) var b = a;

Syntax Error

'eval()' cannot create variables in the surrounding scope.


"use strict";
eval("var a=3;");
console.log(a);

ReferenceError

'implements', 'interface', 'package', 'private', 'protected', 'public', 'static', 'let', and 'yield' are reserved keywords.


"use strict";
// var let = 100; // SyntaxError
var implements = 200;

SyntaxError

Attempts cannot be made to extend a non-extensible object.


"use strict";
var o = {};
Object.preventExtensions(o);
o.a = 10;

TypeError

'eval' and 'arguments' cannot be bound or assigned.


'use strict';
var eval = 17;
arguments++;
++eval;
var obj = { set p(arguments) { } };
var eval;
try { } catch (arguments) { }
function x(eval) { }
function arguments() { }
var y = function eval() { };
var f = new Function('arguments',
  "'use strict'; return 17;");

SyntaxError SyntaxError SyntaxError SyntaxError SyntaxError SyntaxError SyntaxError SyntaxError SyntaxError SyntaxError