CommonJS Vs ESM Vs AMD Vs UMD

Both CommonJS (CJS) and ECMAScript Module (ESM) are used to modulise our code:

  • Prevent variable to expose globally
    • By default variables in JS will be exported globally unless it's wrapped in a function. However with module, the variables will be private to the file.
  • Import code from different files

AMD (Asynchronous Module Definition) and UMD provide some other standard.