Exporting (Literal)

We can export things one member(class, function, or variable) at a time

Things that aren’t exported aren’t available outside the module. This is a way of scoping certain variables, functions to a module, so that it doesn’t collide when you import it.

Look at how in this example we hid the logger x, so now we can define a new logger function in an external file without variable naming collision.

Here’s a more concise syntax where we can remove the export from the left of the members. 

Exporting by Alias

We can also give these members a name that’s different from how their defined in the source file (file were exporting from).

You can also export by default. We’ll get into later, but it makes importing easier

Importing (Literal)

Now let’s get into how we import these members in our target file

Importing with Alias

We can also set the alias name in the import to further avoid conflicts in the namespace.

We can also just import all members with * then access it with .notation

Take Your Javascript Skills to The Next Level

Here at CodingPhase we offer a comprehensive Future-Proof Javascript and ESNEXT – ES6, ES7, ES8 which will cover all the modern Javascript. Hiring managers are looking for people who are up to date with the latest language specifications

Sign up for a monthly subscription for $20/m and also get access to our  Object Oriented Programming with Javascript  and our Learn React by Building a Craigslist Clone