-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReuse_JavaScript_Code_Using_import.js
More file actions
45 lines (31 loc) · 1.23 KB
/
Reuse_JavaScript_Code_Using_import.js
File metadata and controls
45 lines (31 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Reuse JavaScript Code Using import
import allows you to choose which parts of a file or
module to load. In the previous lesson, the examples
exported add from the math_functions.js file.
Here's how you can import it to use in another file:
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 as the
current file.
The relative file path (./) and file extension (.js)
are required when using import in this way.
You can import more than one item from the file by
adding them in the import statement like this:
import { add, subtract } from './math_functions.js';
EXERCISE
Add the appropriate import statement that will allow
the current file to use the uppercaseString 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.
*/
/* This code does not run on local node.js */
import { uppercaseString, lowercaseString } from './string_functions.js';
// Only change code above this line
uppercaseString("hello");
lowercaseString("WORLD!");