1 Answer
1

It does not work because reference does not point to module.exports, it points to the object module.exports points to:

module.exports
\
-> object
/
reference

When you assign a new value to reference, you just change what reference points to, not what module.exports points to:

module.exports
\
-> object
reference -> function

Here is simplified example:

var a = 0;
var b = a;

Now, if you set b = 1, then the value of a will still be 0, since you just assigned a new value to b. It has no influence on the value of a.

i want to understand why it is illegal, even though reference===module.exports is true

It is not illegal, this how JavaScript (and most other languages) work. reference === module.exports is true, because before the assignment, they both refer to the same object. After the assignment, references refers to a different object than modules.export.