-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUse_asterisco_to_Import_Everything_from_a_File.js
More file actions
29 lines (19 loc) · 1.2 KB
/
Use_asterisco_to_Import_Everything_from_a_File.js
File metadata and controls
29 lines (19 loc) · 1.2 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
/*
Use * to Import Everything from a File
Suppose you have a file and you wish to import all of its contents into the current file. This can be done with the import * as syntax. Here's an example where the contents of a file named math_functions.js are imported into a file in the same directory:
import * as myMathModule from "./math_functions.js";
The above import statement will create an object called myMathModule. This is just a variable name, you can name it anything. The object will contain all of the exports from math_functions.js in it, so you can access the functions like you would any other object property. Here's how you can use the add and subtract functions that were imported:
myMathModule.add(2,3);
myMathModule.subtract(5,3);
EXERCISE
The code in this file requires the contents of the file
string_functions.js, that is in the same directory as
the current file.
Use the import * as syntax to import everything from
the file into an object called stringFunctions.
*/
// This code does not work at local node.js
import * as stringFunctions from './string_functions.js';
// Only change code above this line
stringFunctions.uppercaseString("hello");
stringFunctions.lowercaseString("WORLD!");