diff --git a/README.md b/README.md index 91074b2..f66108b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_542 TILs and counting..._ +_543 TILs and counting..._ --- @@ -202,6 +202,7 @@ _542 TILs and counting..._ - [Character Codes from Keyboard Listeners](javascript/character-codes-from-keyboard-listeners.md) - [Computed Property Names In ES6](javascript/computed-property-names-in-es6.md) - [Create An Array Containing 1 To N](javascript/create-an-array-containing-1-to-n.md) +- [Default And Named Exports From The Same Module](javascript/default-and-named-exports-from-the-same-module.md) - [Enable ES7 Transforms With react-rails](javascript/enable-es7-transforms-with-react-rails.md) - [Expand Emojis With The Spread Operator](javascript/expand-emojis-with-the-spread-operator.md) - [Globally Install A Package With Yarn](javascript/globally-install-a-package-with-yarn.md) diff --git a/javascript/default-and-named-exports-from-the-same-module.md b/javascript/default-and-named-exports-from-the-same-module.md new file mode 100644 index 0000000..0e4cfeb --- /dev/null +++ b/javascript/default-and-named-exports-from-the-same-module.md @@ -0,0 +1,35 @@ +# Default And Named Exports From The Same Module + +ES6 module syntax allows for a single default export and any number of named +exports. In fact, you can have both named exports and a default export in +the same module. + +Here is an example: + +```javascript +// src/animals.js +export default function() { + console.log('We are all animals!'); +} + +export function cat() { + console.log('Meeeow!'); +} + +export function dog() { + console.log('Rufff!'); +} +``` + +In this case, you could import the default and named exports like so: + +```javascript +// src/index.js +import animals, { cat, dog } from './animals.js'; + +animals(); // "We are all animals!" +cat(); // "Meeeow!" +dog(); // "Rufff!" +``` + +[source](http://2ality.com/2014/09/es6-modules-final.html)