Sasidhar.com

JavaScript Modules

JavaScript modules are self contained pieces of code that can be reused with other JavaScript modules or in our JavaScript projects. There are mainly 4 different ways we can pack JavaScript code into modules - They are ESM, CJS, AMD and UMD

ESM - ECMAScript modules are the official standard format to package JavaScript code for reuse. So, if you are starting a new project or you get some time to refactor your existing project's code, start with ESM.

As of today ESM support is avaialble across all major browsers (Check Can I use ESM?) as well as in Node.js starting version 8.5.0

ESM vs CJS vs AMD vs UMD

ESM (ECMAScript Modules)

CJS (Common JS)

AMD (Asynchronous Module Definition)

UMD (Universal Module Definition)