Facebook Pixel
Hoisting in Strict Mode JavaScript

What is this in a regular function under strict mode?

The answer

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.

More FAQs in Hoisting in Strict Mode JavaScript

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.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.