Restrictions On Functions

To apply Strict Mode to a function, include "use strict";at the beginning of the function definition. Strict Mode enforces for functions the following:

Functions cannot have duplicated parameter names.


"use strict";
function f(a, a) {}

SyntaxError: Duplicate parameter name not allowed in this context

'arguments' will not reflect any changes made to the parameters.


function f(a) {
  "use strict";
  a *= 2;
  console.log(arguments[0]);
}

f(10);

10

The parameters list must be simple, ie. no default values, no destruturing, no rest operator.


function f(a = 5) {
  "use strict";
  return a;
}

function g({a}) {
  "use strict";
  return a;
}

function h(...a) {
  "use strict";
  return a;
}

SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list

'this' is not boxed into an object in a strict mode function.


'use strict';

function f() {
  console.log(this);
}

f(); // not Window object
f.call(2); // not Number object
f.apply(null); // not Window object
f.call(undefined); // not Window object
f.bind(true)(); // not Boolean object

undefined 2 null undefined true

'arguments.callee', 'f.caller' and 'f.arguments' cannot be used within the function f.


function f() {
  'use strict';
  arguments.callee;
  f.caller;
  f.arguments;
}

f();

TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them

Functions declared in a local block are inaccessible outside the block.


"use strict";

{
  f();
  function f() {
    console.log('hi');
  }
}

f();

hi ReferenceError: f is not defined