Simpler than all previous reasons:
Dr. David Rodenas

The output should be 42? Really? Where does increment get invoked? Where does logCount get invoked? That being said, when those are invoked in the expected order the value logged really is 42. I was skeptical because I thought the integer needed an explicit container but that is not the case. I guess you are highlighting what is by design in CommonJS.

Typescript complains although the transpiled code works (it logs 42):
[ts] Cannot assign to ‘count’ because it is not a variable.

But isn’t Typescript right? Would it not be considered an error if you wrote the increment function like this, instead?

count = count + 1;

Is it legal to re-assign an imported value? According to 16.7.1 In CommonJS, imports are copies of exported values it is legal. Yuck.

Show your support

Clapping shows how much you appreciated Corey Alix’s story.