O'Reilly logo

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond by JD Isaacks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lesson 20. Creating modules

After reading lesson 20, you will

  • Understand what a module is
  • Know how JavaScript behaves in modules
  • Create modules and export values

Before you learn how to create and use ES2015 modules, let’s define what a module in JavaScript is. At its most basic, a module is a JavaScript file that has its own scope and rules, and may import or export values to be used by other modules. A module isn’t an object: it has no data type, and you can’t store one in a variable. It’s simply a tool to break apart, encapsulate, and organize your code.

Modules are a great way to separate your logic into cohesive units and share logic across files without the cumbersome use of global variables. They also allow you to import only what’s ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required