I don't understand the difference in the code below. What's the difference?
A:
const Hoge = require('@foo/hoge');
B:
const {Hoge} = require('@foo/hoge');
thanks
I don't understand the difference in the code below. What's the difference?
A:
const Hoge = require('@foo/hoge');
B:
const {Hoge} = require('@foo/hoge');
thanks
In the first example, Hoge
becomes assigned to the module.exports
value from the module
// @foo/hoge entry file
module.exports = {
Hoge: 123
}
// Your file
const Hoge = require("@foo/hoge")
// Hoge = { Hoge: 123 }
In the second example, you take the property Hoge
out of the object module.exports
// Your file
const { Hoge } = require("@foo/hoge")
// Hoge = 123