6 ECMAScript Modules

This chapter covers

  • Evaluating programmatic module patterns
  • Reviewing Immediately Invoked Function Expressions (IIFEs)
  • Introducing the ECMAScript Module syntax and the new .mjs extension
  • Comparing dynamic and static module systems
  • Using tree-shaking and dead-code elimination

Scope is like oxygen to a programmer. It’s everywhere. You often don’t even think about it. But when it gets polluted . . . you choke.

—David Herman (Effective JavaScript)

The world of JavaScript development is changing frantically, and the part of the language that has undergone the most change is its module system.

In modern application development, we take the notion of modular programming for granted. The practice of breaking our applications ...

Get The Joy of JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.