JavaScript · Middle · Question 36 of 75

How do ES modules differ from CommonJS?

Explanation

import/export are known before execution, which lets bundlers remove unused code (tree-shaking). An imported value reflects the export's current value. require runs at runtime and copies module.exports. ESM is always in strict mode and supports top-level await.

Further reading

Problem with a question

JavaScript · Middle · question 36

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz