In this chapter you will learn one way to export variables from one file, and import them to another.
ES Modules are a complex language feature with many syntax variations and different usage conventions. We will focus on only one reliable and simple approach so you can focus on your program's logic and structure. You will learn how to:
export const name = __;
Export a constant variable from a JS file.import { name } from '<file path>;
Import a constant variable into a file by name.
Practice reading, asserting and writing simple programs that export and import values.
Learn how to use ES Modules to separate your functions and unit tests into two separate files. Exercises include:
- Refactoring functions and unit tests from one file to two files.
- Writing unit tests in one file to describe a function declared in a different file.
- Writing a function in one file to pass unit tests in a separate file.