Course contentsShow
← JavaScript
Lesson 98 of 2,7233. Variables and ScopeFree lesson

Import Hoisting Behavior

How ES module imports are hoisted to the top, making them available throughout the module scope.

Import Hoisting Behavior

What you'll learn: How ES module imports are hoisted, making them available throughout your entire module.


What Happens to Imports

When you use ES module syntax (import ... from ...), JavaScript hoists those import statements to the very top of your module — even before any other code runs. This means imported values are available anywhere in your module file, regardless of where you physically write the import statement.

This is similar to how function declarations are hoisted, but with one key difference: imports are processed before anything else, including function declarations.

Why This Matters

Because imports are hoisted, you can actually use an imported value before the line where you write the import statement:

// This works fine!
console.log(myFunction());

import { myFunction } from './utils.js';

Even though the import appears after the function call, JavaScript moves it to the top during the parsing phase, so myFunction is already available when the code executes.

How It Differs from Variable Hoisting

Remember that let and const have a Temporal Dead Zone — you can't use them before their declaration. Imports don't have a TDZ. They're fully initialized and available throughout the entire module scope from the start.

Think of imports like setting up your workspace before you begin work: JavaScript gathers all your imports first, fetches the modules, and makes everything ready before running any of your code.


Key Takeaway: ES module imports are hoisted to the top and fully available throughout the entire module scope, with no Temporal Dead Zone — you can use imported values anywhere in your module file.