4 ms·
> On the other hand, ESM CAN have unnamed "default" export and CAN have arbitrary number of named exports. To nitpick on the nitpick: ESM only has named export
by jkrems 6y ago
> On the other hand, ESM CAN have unnamed "default" export and CAN have arbitrary number of named exports.
To nitpick on the nitpick: ESM only has named exports. It just treats the export named "default" differently in some scenarios and has special syntax for it.
So, roughly:
* CJS: Exports a single value which may or may not be an object. When assigning the exported value to local variables, destructuring can be used to access individual exports properties.
* ESM: Exports a namespace of named bindings. When importing the bindings to local aliases, the name of the alias can be changed using `as`. There's special syntax for importing the binding with the name "default".
It's somewhat unfortunate that the syntax _looks_ so close without being all that close.