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

Javascript Export and Import

The document outlines the differences between ES5 (CommonJS Modules) and ES6 (ECMAScript Modules) regarding export and import syntax. It details single and multiple exports, named exports, default exports, and the ability to rename imports. Additionally, it provides notes on valid and invalid arrow function exports.

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)
2 views1 page

Javascript Export and Import

The document outlines the differences between ES5 (CommonJS Modules) and ES6 (ECMAScript Modules) regarding export and import syntax. It details single and multiple exports, named exports, default exports, and the ability to rename imports. Additionally, it provides notes on valid and invalid arrow function exports.

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.

Arrow Function Export Notes: -

-Valid:

export default (a, b) => a + b; //anonymous default export

- Valid:

const add = (a, b) => a + b;

export default add; //named function exported later

- Invalid:

export default const add = (...) //Invalid syntax

You might also like