About exports; module.exports ; export; export default distinguish

Time:2020-11-22
1. About exports and module.exports (node is operational)
  • When a node executes a file, an exports and module object will be generated in the file,
    Module has an exports attribute.
  • exports = module.exports = {};

exports.js

var frist1 = 1
module.exports = frist1

importm.js

const frist1 = require('./exports.js');
console.log(frist1)

Run: node importm.js

2. About export and export default
  • Both export and export default can be used to export constants, functions, files, modules, etc
  • In a file or module, there can be multiple export and import, and only one export default
  • To export through export mode, you need to add {} when importing, but do not need to use export default
  • Export can directly export variable expressions, but export default cannot.

reference resources:
https://blog.csdn.net/weixin_40817115/article/details/81534819

https://segmentfault.com/a/1190000010426778

Recommended Today

Array of algorithms — sum of three numbers

Sum of three numbers difficultysecondary Here is an array of N integersnums, judgmentnumsAre there three elements a, B, C in a such that a + B + C = 0? Please find all triples that satisfy the condition and do not repeat.be careful:The answer cannot contain duplicate triples. Example:Given array nums = [- 1, 0, […]