[JS]: import/export snippets

JS

09/26/2019


Export

Default Export

person.js

JS
export default const person = {
name: "Ellis",
}
// OR
const person = { ... }
export default person

Named Export

util.js

JS
export const func1 = () => { ... }
export const func2 = () => { ... }
// OR
const fun1 = () => { ... }
const fun2 = () => { ... }
export = { func1, func2 }

Import

JS
import p from "./person.js" // Can assign any name for named export
// Must use the same name assigned in util.js but can assign alias
import { func1, func2 } from "./util.js"

alias

JS
import { func1 as firstFcn, func2 as secondFcn } from "./util.js"

*

JS
// Usage: functions.func1 / functions.func2
import * as functions from "./util.js"

WRITTEN BY

Keeping a record