Imports and Exports
We can use the keyword
export to expose values for importing.
Named imports and exports
A single file can have multiple exports, and any subset of these can be imported simultaneously.
Importing from modules
3rd party libraries specify a "main" file, usually named
There's a shorter syntax for importing this file: we import the name of the module's directory (which is the name of the package in the
E.g. assuming we had downloaded the
Similarly, importing a directory will import the
index.jsfile in that directory.
"Legacy" imports and exports
export syntax are usually implemented as syntax sugar on top of the older
The new syntax is generally better since it's statically analyzable — i.e. we can't use an expression as an import path.
There are still a variety of uses for this pattern, but in the most common use case, we should use
exporton any platform that supports them.