0

This is my script in a file named foo.js.

console.log(this === module.exports)

This gives the expected output, i.e. true.

$ node foo.js
true
$ node
> require('./foo')
true
{}

But I am unable to understand why the following produces the opposite output, i.e. false.

$ node
> console.log(this === module.exports)
false
undefined
> .load foo.js
> console.log(this === module.exports)
false
undefined

What is this defined to in the node shell?

Lone Learner
  • 18,088
  • 20
  • 102
  • 200

0 Answers0