I ran across some code in a NodeJS application recently that boils down to the following:
Why is line 4 of the first file written like that? If I understand correctly, the comma expression in the parens evaluates both operands and has a value equal to the second, so the value of the comma expression is the B.b function. B.b is then called with a as an arg and the result is assigned back to a. As you might expect, the output of the code is "a is now 3". I see what it's doing, but what was the point of using (0, B.b) instead of just plain B.b?
The code was too nicely indented and commented for this to be obfuscation tactic.
Aha!!! It turns out I left out some code that I didn't realize had a bearing on the question. Here's some new and improved code:
When B.b() is called from line 5 of A.js, the "this" inside of b() is "global" so this.console.log() is valid, and everything works fine.
However, when B.b() is called as in line 6, "this" is the function b(), so this.console is undefined and the function this.console.log() is not found so a TypeError is thrown.
In the real code I found this in, the B.b() function never actually used "this" for anything, so that didn't trigger any alarms. I guess A.js is using the (0, B.b) idiom to make sure B.b is executed in the global context in case it ever does use "this".
I apologize for not providing all the relevant code the first time around.
Disclaimer: I still don't quite get all the subtle details, but I at least know what to google do a web search for now.