Back to search

Modules in JavaScript: import/export, default export, named export, and CommonJS vs ES modules

Modern JavaScript uses modules to organize code, with ES modules in the language standard and CommonJS still common in older Node.js code.

JavaScript Medium Theory

Modules in JavaScript: import/export, default export, named export, and CommonJS vs ES modules

Modern JavaScript uses modules to organize code, with ES modules in the language standard and CommonJS still common in older Node.js code.

  • Named and default exports behave differently
  • ES modules use `import` and `export`
  • CommonJS uses `require` and `module.exports`

Modules in JavaScript: import/export, default export, named export, and CommonJS vs ES modules