-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.exporting.js
35 lines (30 loc) · 1.01 KB
/
10.exporting.js
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
/*
* This file shows exporting as specified by CommonJS, the version traditionally used in Node.js, but not the way indiciated in the ECMASCRIPT specification.
* Exporting allows constructs in one file to be made available in another.
* Any kind of value can be exported: numbers, strings, arrays, functions, objects, etc
*
* https://eloquentjavascript.net/10_modules.html (Note that Node.js uses CommonJS-style exports/require by default)
*/
// an object
const foo = {
age: 72,
name: "Foo Barstein",
email: '[email protected]',
address: {
street: '92 Rue Jamil Sedki',
city: 'Beni Brahim',
country: 'Tunisia',
postalCode: 7040
}
};
// a function
const bar = () => {
console.log('Thank you for calling bar!');
};
// a simple value
const baz = 3.14;
// export these all to make them available for import into another file
// see the 11.importing.js file for example
module.exports = {foo , bar, baz};
console.log('\n-- Exporting --');
console.log(module.exports);