import
allows you to choose which parts of a file or module to load. In the previous lesson, the examples exported add
from the file math_functions.js
. Here's how you can import them into another file:
```js
import { add } from './math_functions.js';
```
Here, import
will find add
in math_functions.js
, import just that function for you to use, and ignore the rest. The ./
tells the import to look for the math_functions.js
file in the same folder that the file which uses the import statement is. The relative file path (./
) and file extension (.js
) are required when using import in this way.
You can import multiple items like this:
```js
import { add, subtract } from './math_functions.js';
```
import
statement that will allow the current file to use the capitalizeString
and lowerCaseString
functions you exported in the previous lesson. These functions are in a file called string_functions.js
, which is in the same directory as the current file.
capitalizeString
.
testString: getUserInput => assert(getUserInput('index').match(/import\s*\{\s*capitalizeString\s*\}\s*from\s*("|')(\.\/string_functions|string_functions)\1(|\/\/|;\s|\s)/g));
- text: You should properly import lowerCaseString
.
testString: getUserInput => assert(getUserInput('index').match(/import\s*\{\s*capitalizeString\s*\}\s*from\s*("|')(\.\/string_functions|string_functions)\1(|\/\/|;\s|\s)/g));
```