Skip to main content

JavaScript Dynamic Import — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Dynamic Import lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Load a module dynamically

    easy10 min

    Simulate import() with a promise and use its export.

  2. 2

    Await a dynamic import

    easy10 min

    Use async and await to load a simulated module.

  3. 3

    Load conditionally

    easy10 min

    Only load the module when it is actually needed.

  4. 4

    Handle a failed import

    easy10 min

    Catch a rejected dynamic import and report the message.

  5. 5

    Destructure the resolved module

    medium10 min

    Pull two exports straight out of the resolved value.

Find the bug(5)

  1. 1

    Fix the module used without waiting

    easy8 min

    The result is a promise until it resolves.

  2. 2

    Fix await missing inside the async function

    easy8 min

    Without await, math is a promise, not the module.

  3. 3

    Fix the module loaded even when not needed

    easy8 min

    The module should only load when the condition is actually true.

  4. 4

    Fix the error message discarded

    easy8 min

    The catch block should report the real error, not a fixed message.

  5. 5

    Fix the destructuring done too early

    easy8 min

    The module has not resolved yet when the names are pulled out.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace