// math.js
module.exports = function add(a, b) {
return a + b;
};
// main.js
const add = require('./math');
console.log(add(2, 3));What does
main.js print when it runs?- a5✓
- b23
- cundefined
- dTypeError: add is not a function
Explanation:
module.exports is set to the add function itself, so require('./math') returns that function directly. Calling add(2, 3) computes 2 + 3, which is 5.