December 2017
Beginner to intermediate
376 pages
7h 53m
English
A solution to the dependency management problem is to use a module system, such as CommonJS or native ES modules. These systems allow JavaScript code to be modularized and imported into other files.
Here is a CommonJS example:
// moduleA.js module.exports = function(value) { return value * 2; } // moduleB.js var multiplyByTwo = require('./moduleA'); console.log(multiplyByTwo(2)); // Output: 4
And here is a Native ES modules example:
// moduleA.js export default function(value) { return value * 2; } // moduleB.js import multiplyByTwo from './moduleA';console.log(multiplyByTwo(2));// Output: 4
The problem is that CommonJS cannot be used in a browser (it was designed for server-side JavaScript) and native ES modules are only now getting ...
Read now
Unlock full access