Chapter 12

Using JavaScript Modules

IN THIS CHAPTER

Bullet Introducing modules

Bullet Creating modules with export

Bullet Using modules with import

Bullet Giving your module a name

Bullet Setting a default export

Bullet Loading modules dynamically

Bullet Using modules with HTML files

“Divide each difficulty into as many parts as is feasible and necessary to resolve it.”

—RENE DESCARTES

Until now, every JavaScript program you've written has been in a single file, which is fine for small programs and examples. But, in real-life programming, a program may have thousands of lines of code. Keeping everything in a single file in a large program would make your code impossible to maintain.

To keep your code organized, to enable multiple people to work on a project, and to help you think about your code more easily, JavaScript provides a ...

Get JavaScript All-in-One For Dummies 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.