-1

How does module.exports work for an object without keys? For example, if I have in test.js

const two = 2;
const three = 3;
module.exports = {two, three};    // Is the right-hand side an object? If so, where are its keys?
                                  // It doesn't look like it's object destructuring.

and in app.js

const test = require("./test");
console.log(test.two);            // 2
console.log(test.three);          // 3
Leponzo
  • 298
  • 4
  • 15
  • It's not anything specific to `module.exports` - that's just the shorthand for object creation introduced in ES6 – VLAZ Mar 16 '20 at 17:44

1 Answers1

0

This:

module.exports = {two, three};

is a shorthand notation for:

module.exports = {two: two, three: three};

Both generate the exact same object. This has nothing specially to do with module.exports. It's just an ES6 object initializer shorthand way of declaring an object where you want the property name to be the same as your variable name.

Leponzo
  • 298
  • 4
  • 15
jfriend00
  • 580,699
  • 78
  • 809
  • 825