Skip to content

Instantly share code, notes, and snippets.

@shreshthmohan
Created March 9, 2022 05:35
Show Gist options
  • Save shreshthmohan/89fba16fab5c452dd26f1bc346354199 to your computer and use it in GitHub Desktop.
Save shreshthmohan/89fba16fab5c452dd26f1bc346354199 to your computer and use it in GitHub Desktop.
Named and default imports, exports in JavaScript (ES Modules)
// Named export
export const data = { a: 2, b: 3 }
// There can be multiple named export from one file
// Another named export
export const data1 = { c: 2, d: 3 }
const content = 'Hello'
// Default export
export default content
// There can be only one default export per file
// Can't do multiple default exports
// This won't work:
// const content1 = "World"
// export default content1
// . means current folder
// .. means parent folder (One folder above current folder)
// / means go inside folder
// ./ means inside current folder
// .data.js . at the start of the file name means hidden file
// import default
import content from './sampleexport.js'
// named import
import { data } from './sampleexport.js'
console.log(content, data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment