Function scoping in strict mode

suggest change

In Strict Mode, functions declared in a local block are inaccessible outside the block.

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

In strict mode the declaration is scoped to the block, but it is hoisted inside that block, so the call above the declaration runs. A let or const binding would still be in the temporal dead zone there. Sloppy-mode block functions follow older, less predictable rules.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents