JavaScript Modules

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • import defaultMember from 'module';
  • import { memberA, memberB, ... } from 'module';
  • import * as module from 'module';
  • import { memberA as a, memberB, ... } from 'module';
  • import defaultMember, * as module from 'module';
  • import defaultMember, { moduleA, ... } from 'module';
  • import 'module';

Remarks

From MDN (emphasis added):

This feature is not implemented in any browsers natively at this time. It is implemented in many transpilers, such as the Traceur Compiler, Babel or Rollup.

Many transpilers are able to convert ES6 module syntax into CommonJS for use in the Node ecosystem, or RequireJS or System.js for use in the browser.

It is also possible to use a module bundler like Browserify to combine a set of inter-dependent CommonJS modules into a single file which can be loaded in the browser.



Got any JavaScript Question?