bhylu.com

Advertisements

Modules Intro

Modules split code into files with explicit imports and exports. Run them from a local web server with a module script entry point.

Where to run this

Use a local browser project for this example. It needs browser permissions, additional files, a server endpoint, or a library as described below. The restricted playground cannot provide those dependencies.

A practical example

JavaScript

// maths.js
export function total(price, count) {
  return price * count;
}
// app.js: import {total} from "./maths.js";
// console.log(total(6, 2));

What happens

The app file can import the named function and calculate 12.