Skip to content

Instantly share code, notes, and snippets.

@masautt
Created September 3, 2019 21:42
Show Gist options
  • Save masautt/a852fda69525b9671ba6a86df9a822cb to your computer and use it in GitHub Desktop.
Save masautt/a852fda69525b9671ba6a86df9a822cb to your computer and use it in GitHub Desktop.
How can I include a JavaScript file in another JavaScript file?
// EXPORTING A DEFAULT
// separateFile.js
export default function foo() {
console.log("bar");
}
// index.js
import foo from "./separateFile"
foo(); //--> "bar"
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//EXPORTING WITHOUT SETTING A DEFAULT
//seperateFile.js
export function foo() {
console.log("bar");
}
// index.js
import {foo} from "./separateFile"
foo(); //--> "bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment