What is module scope in ES modules and how does `import` differ from CommonJS `require()`?

JavaScript Developer Hard

JavaScript Developer — Hard

What is module scope in ES modules and how does `import` differ from CommonJS `require()`?

Key points

  • ES modules prevent global leakage with their own scope
  • Static import/export in ES enables tree-shaking
  • CommonJS require() returns a copy of exports
  • ES imports are live bindings to original exports

Ready to go further?

Related questions