-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson_9.js
More file actions
100 lines (29 loc) · 842 Bytes
/
lesson_9.js
File metadata and controls
100 lines (29 loc) · 842 Bytes
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
// Import / Export
//NAMED EXPORTS
//---------lib.s-------------
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(7));
}
// Import PART OF A MODULE
//-------main.js---------
import { square, diag } from 'lib';
console.log(square(11));
console.log(diag(4, 3));
// IMPORTING COMLETE MODULE
//------main.js--------
import * as lib from 'lib';
console.log(lib.square(11));
console.log(lib.diag(4, 3));
// IMPORTING WITH MORE CONVENIENT ALAIS
import{reallyReallyLongModuleMemberName as shortName}
from 'my-module';
// SINGLE DEFAULT EXPORT
//-----myFunc.js-----
export default function () { ... } // no semicolon!
//------main1.js--------
import myFunc from 'myFunc';
myFunc();