Hoisting in Strict Mode JavaScript
Strict mode changes some hoisting-related behavior. Here is what is different and why it matters.
Hoisting in Strict Mode JavaScript
Strict mode ("use strict") changes a few hoisting-related behaviors in JavaScript. ES modules are strict by default.
What Strict Mode Changes
- Assigning to an undeclared variable throws: Without strict mode,
x = 5creates a globalvar x. In strict mode, it throwsReferenceError: x is not defined. thisin regular functions isundefined: Not the global object. This affects hoisting ofthisin callbacks.- Duplicate parameter names throw:
function foo(a, a) {}throws in strict mode. - Duplicate property names in objects: allowed in ES5 strict, throws in some later contexts.
What Strict Mode Does Not Change
- Hoisting itself still happens.
var,let,const, and function declarations are still hoisted during the memory phase. - The TDZ still applies to
letandconst. - Function declarations are still hoisted with their full body.
Example: Undeclared Variable
"use strict"; function foo() { bar = 10; // ReferenceError: bar is not defined return bar; } foo();
Without strict mode, this would create window.bar = 10 silently.
Example: this in Strict Functions
"use strict"; function showThis() { console.log(this); // undefined } showThis();
Without strict mode, this would be window. This matters when a hoisted function is called before any binding.
ES Modules Are Strict by Default
You do not need "use strict" in a module. import and export automatically enable strict mode. Top-level this is undefined in modules.
Why This Matters
Strict mode surfaces bugs that sloppy mode hides. It prevents accidental globals, makes this predictable, and catches duplicate declarations. Combined with let/const, it gives you a safer hoisting story.
The Takeaway
Strict mode does not disable hoisting, but it makes related bugs visible. Undeclared assignments throw, this is undefined in regular functions, and duplicate parameters throw. ES modules are strict by default, so modern code gets these protections automatically.
No. Hoisting still happens. var is hoisted with undefined, function declarations with their full body, and let/const sit in the TDZ. Strict mode does not change the hoisting mechanism itself.
It makes related bugs visible. Assigning to an undeclared variable throws ReferenceError instead of creating a global. this is undefined in regular functions instead of the global object. Duplicate parameter names throw.
Yes. Any file with import or export is automatically in strict mode. You do not need 'use strict'. Top-level this is undefined in modules, not the global object.
It throws ReferenceError: x is not defined. In sloppy mode, it would silently create a global variable on the window object, which is a common source of bugs.
undefined. In sloppy mode, this defaults to the global object (window in browsers). Strict mode removes this default, so calling a function without a receiver gives this as undefined.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

