Wednesday, 12 April 2017

Command line JavaScript occasionally not printing value

While I write javascript and I'm unsure of its behavior I like to run it through node's REPL shell to verify that it works as intended.

When I was testing a minified enclosed function I noticed some odd behavior with node: Occasionally it doesn't output any value.

No output

It doesn't "reliably" occur, though I find I can get it to occur the most often when I attempt to use 2 different expressions.

Question: Why is this happening? Is this a common occurrence that I have just never come across before?

Here are the code segments I used in the example:

var testObj = { val1: false, val2: false };

!function(){for(var a in testObj)if(testObj.hasOwnProperty(a)&&!a)return!0}();

(function(){for(var a in testObj){if(testObj.hasOwnProperty(a)&&!a)return !0;}return !1;})();

Notes:

  1. I have seen both functions produce this bug.
  2. I have seen both functions do this on the first evaluation before I alternated between the two.
  3. I have not tested this with other functions: only ones searching through an object's properties.

Node v6.10.0 Windows 10 x64



via Patrick Barr

No comments:

Post a Comment