I am not no expert but import is similar to require in many ways, but the key difference are:
you can import selective items using import( guess this is close to python), but with require, you export only a single module as a namespace, everything else is it's sub-modules.
second is, require is more of of node.js thingy(though you can bring it into browser using browserify ),, but import is now a native feature of ES6, i.e browsers that support ES6, import would work
Example from lukehoban's es6features to re-enforce my first point:
// lib/math.js
export function sum(x, y) {
return x + y;
}
export var pi = 3.141593;
// app.js
import * as math from "lib/math";
alert("2π = " + math.sum(math.pi, math.pi));
// otherApp.js
import {sum, pi} from "lib/math";
alert("2π = " + sum(pi, pi));
//Some additional features include export default and export *:
// lib/mathplusplus.js
export * from "lib/math";
export var e = 2.71828182846;
export default function(x) {
return Math.log(x);
}
// app.js
import ln, {pi, e} from "lib/mathplusplus";
alert("2π = " + ln(e)*pi*2);
import foo from ...only works if the imported module has a default export. Everything you need to know should be contained in developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… .