the difference between Require/exports and Import/export.
Require/export and Import/export are the concepts that belong to two different norms: Require/exports belong to the COMMONJS specification, Nodejs is the implementation of the specification. Import/export belongs to the ES2015 specification (ES6), which is more normative and authoritative than COMMONJS.
At present, ES6 is mainly converted to ES5 by Babel, so the written import/export is converted to Babel by Require/exports. Both can be viewed as outputting an object and introducing an object and using its properties or methods. difference between
The main difference between Require/exports and Import/export is the form of writing:
Require/exports's writing
const FOO = require ("./foo");
Exports is a reference to Module.exports and is described in detail below.
exports.foo = foo;
Module.exports = foo;
Import/export the writing
import foo from "./foo"
import {foo} from "./foo"
import * as Foo from "./foo"
Export Default foo
export const foo
export * from "foo"
the difference between exports and Module.exports:Exports is a module.exports reference, that is, the exports pointer points to the Module.exports memory address. Require only accept module.exports not accept exports
Exports and Module.exports are both object types, which are reference type data, and the exports memory address and module.exports memory address are the same. The simple thing is that one of them has changed, and the other one has changed.
Exports.foo = "stupid"
console.log (module.exports.foo)
//stupid
//But when the exports point to another object, the situation is different.
At this point the exports memory address points to a new object.
exports = {
foo: "Stupid"
}
console.log (Module.exports.foo = = Exports.foo)
//false