Skip to main content
FREE Mock interview & resume review with Sumit. Free right now, no payment needed.Book a slot

ES6 Modules in JavaScript

Learn how to organize code using ES6 import and export.

jiocoder TeamUpdated Jun 6, 20261 min readJavaScript
ES6 Modules in JavaScript

Exporting#

Code
// Named exports
export const name = 'John';
export function greet() {
  return 'Hello';
}

// Default export
export default function App() {
  return 'App';
}

// Export list
export { name, greet };

Importing#

Code
// Named imports
import { name, greet } from './module.js';

// Default import
import App from './App.js';

// Import all
import * as utils from './utils.js';

// Renaming
import { name as userName } from './module.js';

Dynamic Imports#

Code
// Dynamic import
const module = await import('./module.js');
const { name } = await import('./module.js');

Article discussion

(0)

Join the discussion — login to comment and help other developers.

Login to comment