-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUse_export_to_Share_a_Code_Block.js
More file actions
56 lines (43 loc) · 1.32 KB
/
Use_export_to_Share_a_Code_Block.js
File metadata and controls
56 lines (43 loc) · 1.32 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
46
47
48
49
50
51
52
53
54
55
56
/*
Use export to Share a Code Block
Imagine a file called math_functions.js that contains
several functions related to mathematical operations.
One of them is stored in a variable, add, that takes in
two numbers and returns their sum.
You want to use this function in several
different JavaScript files.
In order to share it with these other files,
you first need to export it.
export const add = (x, y) => {
return x + y;
}
The above is a common way to export a single function,
but you can achieve the same thing like this:
const add = (x, y) => {
return x + y;
}
export { add };
When you export a variable or function, you can import
it in another file and use it without having to rewrite
the code. You can export multiple things by repeating
the first example for each thing you want to export, or
by placing them all in the export statement of the
second example, like this:
export { add, subtract };
EXERCISE:
There are two string-related functions in the editor.
Export both of them using the method of your choice.
*/
/* This runs ok at freecodecamp interface
But it does not run at local node.js
*/
const uppercaseString = (string) => {
return string.toUpperCase();
}
const lowercaseString = (string) => {
return string.toLowerCase()
}
export {
uppercaseString,
lowercaseString
};