0% found this document useful (0 votes)
0 views1 page

Import Export Js

The document outlines the export and import syntax for CommonJS and ECMAScript modules. It details single and multiple exports, named exports, default exports, and dynamic imports with corresponding syntax examples. The information serves as a guide for using module systems in JavaScript.

Uploaded by

nebsdev1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views1 page

Import Export Js

The document outlines the export and import syntax for CommonJS and ECMAScript modules. It details single and multiple exports, named exports, default exports, and dynamic imports with corresponding syntax examples. The information serves as a guide for using module systems in JavaScript.

Uploaded by

nebsdev1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ES5 (CommonJS Modules)

Type Export Syntax Import Syntax Definition


Exports a single item
Single module.exports = const x =
value require('./file') from a file (function,
Export
object, etc.).
Exports multiple named
Multiple module.exports = const { a, b } =
{ a, b } require('./file') items as properties of an
Exports
object.
Named Shorthand to export
const { a } =
Export exports.a = value multiple values via the
require('./file')
Shortcut exports object.

ES6 (ECMAScript Modules)

Type Export Syntax Import Syntax Definition


export const x
Named = ... import { x, y } from Export variables or
Export export function './file.js' functions by name.
y() {}
Default export default Exports a single default
import x from './file.js'
Export something value per file.
Multiple import { a, b } from Group and export
export { a, b }
Exports './file.js' multiple identifiers.
Import with import { a as x } from Rename named import
— './file.js'
Rename during import.
export default
Mixed something import x, { a } from Import default and
Import export const a './file.js' named exports together.
= ...
export * from import { a } from Re-export all exports
Export All './file.js' './file.js' or re-exported file from another module.
Loads a module
Dynamic const module = await
— import('./file.js') asynchronously at
Import
runtime.

You might also like