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.


RESETRUNFULL
<!DOCTYPE html><html><body><script>

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

</script></body><html>

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


RESETRUNFULL
<!DOCTYPE html><html><body><script>

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

</script></body><html>

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


RESETRUNFULL
<!DOCTYPE html><html><body><script>

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

</script></body><html>

<!DOCTYPE html><html><body><script>

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

</script></body><html>

<!DOCTYPE html><html><body><script>

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

</script></body><html>

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


RESETRUNFULL
<!DOCTYPE html><html><body><script>

'use strict';function f() { console.log(this); }f();                      // undefined, not Window objectf.call(2);              // 2, not Number objectf.apply(null);        // null, not Window objectf.call(undefined);  // undefined, not Window objectf.bind(true)();      // true, not Boolean object

</script></body><html>

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


RESETRUNFULL
<!DOCTYPE html><html><body><script>

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

</script></body><html>

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


RESETRUNFULL
<!DOCTYPE html><html><body><script>

"use strict";{
  f(); // 'hi'
  function f() {console.log('hi');}}f(); // ReferenceError: f is not defined

</script></body><html>