File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,27 @@ ECMAScript modules are [the official standard format][] to package JavaScript
1313code for reuse. Modules are defined using a variety of [ ` import ` ] [ ] and
1414[ ` export ` ] [ ] statements.
1515
16+ The following example of an ES module exports a function:
17+
18+ ``` js
19+ // addTwo.js
20+ function addTwo (num ) {
21+ return num + 2 ;
22+ }
23+
24+ export { addTwo };
25+ ```
26+
27+ The following example of an ES module imports the function from ` addTwo.js ` :
28+
29+ ``` js
30+ // app.js
31+ import { addTwo } from ' ./addTwo.js' ;
32+
33+ // Prints: 6
34+ console .log (addTwo (4 ));
35+ ```
36+
1637Node.js fully supports ECMAScript modules as they are currently specified and
1738provides limited interoperability between them and the existing module format,
1839[ CommonJS] [ ] .
You can’t perform that action at this time.
0 commit comments