// math.js
module.exports = function add(a, b) {
return a + b;
};
// main.js
const add = require('./math');
console.log(add(2, 3));main.js çalıştığında ne yazdırılır?- a5✓
- b23
- cundefined
- dTypeError: add is not a function
Açıklama:
module.exports, add fonksiyonunun kendisine eşitlenmiştir; bu yüzden require('./math') doğrudan bu fonksiyonu döndürür. add(2, 3) çağrısı 2 + 3 işlemini yapar ve sonuç 5 olur.