Skip to content

Instantly share code, notes, and snippets.

@bterlson
Last active January 26, 2017 15:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bterlson/2a7298c506db36ebb6f3 to your computer and use it in GitHub Desktop.
Save bterlson/2a7298c506db36ebb6f3 to your computer and use it in GitHub Desktop.
Module export forms have subtle differences
// exporter1.js
let foo = 1;
export { foo as default }; // exports the foo binding
foo = 2;
// exporter2.js
let foo = 1;
export default foo; // creates a new binding named *default* and initializes it to 1.
foo = 2; // assigns to the foo binding which is not exported
// importer1.js
import foo from "exporter1.js";
print(foo); // 2
// importer2.js
import foo from "exporter2.js";
print(foo); // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment