Node.js · Junior · Question 13 of 75
Why does exports = { add } not export anything in CommonJS?
- 1Because
exportsis read-only and throws an error - ✓Correct answer: It only reassigns the local
exportsvariable;require()still returns the originalmodule.exportsobject - 3Because objects cannot be exported in CommonJS
Explanation
exports starts as a reference to module.exports. Adding properties (exports.add = add) works, but assigning a new object breaks the link. Use module.exports = { add } instead.