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
  • 15,013
  • 17
  • 83
  • 176

0 Answers0