Skip to content

Commit 7a8b22d

Browse files
authored
1 parent 7bebfa2 commit 7a8b22d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

readme.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ When you struggle to understand a notion, I suggest you look for answers on the
7878
- [External resources](#external-resources-2)
7979
+ [Imports / Exports](#imports--exports)
8080
- [Explanation with sample code](#explanation-with-sample-code-1)
81+
* [Named exports](#named-exports)
82+
* [Default import / export](#default-import--export)
8183
- [External resources](#external-resources-3)
8284
+ [JavaScript *this*](#-javascript-this)
8385
- [External resources](#external-resources-4)
@@ -1023,7 +1025,7 @@ I highly recommend to take a look at MDN resources on import/export (see externa
10231025

10241026
#### Explanation with sample code
10251027

1026-
- Named exports
1028+
##### Named exports
10271029

10281030
Named exports are used to export several values from a module. You can only name-export variables (not functions or class), so if you want to name-export a function, you have to store it in a variable before.
10291031

@@ -1048,7 +1050,15 @@ console.log(constants.pi) // 3.14
10481050
console.log(constants.exp) // 2.7
10491051
```
10501052

1051-
- Default import / export
1053+
While named imports looks like *destructuring*, they have a different syntax and are not the same. They don't support default values nor *deep* destructuring.
1054+
1055+
Besides, you can do aliases but the syntax is different from the one used in destructuring:
1056+
1057+
```js
1058+
import { foo as bar } from 'myFile.js'; // foo is imported and injected into a new bar variable
1059+
```
1060+
1061+
##### Default import / export
10521062

10531063
Concerning the default export, there is only a single default export per module. A default export can be a function, a class, an object or anything else. This value is considered the "main" exported value since it will be the simplest to import. [Ref: MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Description)
10541064

@@ -1082,9 +1092,12 @@ console.log(result) // 3
10821092

10831093
#### External resources
10841094

1095+
- [ES6 Modules in bulletpoints](https://ponyfoo.com/articles/es6#modules)
10851096
- [Export - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)
10861097
- [Import - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)
10871098
- [Understanding ES6 Modules](https://www.sitepoint.com/understanding-es6-modules/)
1099+
- [Destructuring special case - import statements](https://ponyfoo.com/articles/es6-destructuring-in-depth#special-case-import-statements)
1100+
- [Misunderstanding ES6 Modules - Kent C. Dodds](https://medium.com/@kentcdodds/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution-ad2d5ab93ce0)
10881101
- [Modules in JavaScript](http://exploringjs.com/es6/ch_modules.html#sec_modules-in-javascript)
10891102

10901103
### <a name="this_def"></a> JavaScript *this*

0 commit comments

Comments
 (0)