You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I run this in the node REPL, it gives me an odd result:
xxxxx@xxxxx:~/Desktop$ node -v
v6.3.1
xxxxx@xxxxx:~/Desktop$ node
> var t = require('./test.js');
undefined
> t([1, 2]); <<<--- Passing in [1, 2] whose constructor should be Array
false <<<--- What?!
> [1, 2].constructor === Array;
true
> var tprime = function(a) {return a.constructor === Array;};
undefined
> tprime([1, 2]);
true
Since t is simply checking whether the constructor of its argument is Array, I was expecting a true when you passed in [1, 2] whose constructor is, in fact, an Array.
Running Problem Code against LTS
I ran the exact same test after uninstalling v6.3.1 and installing v4.4.7 and the problem disappears:
xxxxx@xxxxx:~/Desktop$ node -v
v4.4.7
xxxxx@xxxxx:~/Desktop$ node
> var t = require('./test.js');
undefined
> t([1, 2]);
true <<<--- As expected
> [1, 2].constructor === Array;
true
> var tprime = function(a) {return a.constructor === Array;};
undefined
> tprime([1, 2]);
true
>
Checking against String
The problem also disappears if I change test.js to check against String instead of Array (in both v6.3.1 and v4.4.7). Here is the new test.js:
xxxxx@xxxxx:~/Desktop$ node -v
v6.3.1
xxxxx@xxxxx:~/Desktop$ node
> var t = require('./test.js');
undefined
> t("sdfdsf");
true <<<--- No issue this time
> "sdfdsf".constructor === String;
true
> .exit
xxxxx@xxxxx:~/Desktop$ node -v
v4.4.7
xxxxx@xxxxx:~/Desktop$ node
> var t = require('./test.js');
undefined
> t("sdfdsf");
true
> "sdfdsf".constructor === String;
true
> .exit
Veritas@nfr:~/Desktop$
Conclusion
Thus, in conclusion, is there a real bug here or is this a known valid difference between Node versions v4.x.x and #v6.x.x?
The text was updated successfully, but these errors were encountered:
addaleax
added
duplicate
Issues and PRs that are duplicates of other issues or PRs.
repl
Issues and PRs related to the REPL subsystem.
labels
Jul 27, 2016
v6.3.1
Darwin xxxxx.local 15.6.0 Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64
Problem Statement
The simplest instance of the problem is this: I have a file, say
test.js
in my Desktop, containing the following code:When I run this in the node REPL, it gives me an odd result:
Since
t
is simply checking whether the constructor of its argument isArray
, I was expecting atrue
when you passed in[1, 2]
whose constructor is, in fact, anArray
.Running Problem Code against LTS
I ran the exact same test after uninstalling
v6.3.1
and installingv4.4.7
and the problem disappears:Checking against String
The problem also disappears if I change
test.js
to check againstString
instead ofArray
(in bothv6.3.1
andv4.4.7
). Here is the newtest.js
:And here are the checks in REPL:
Conclusion
Thus, in conclusion, is there a real bug here or is this a known valid difference between Node versions
v4.x.x
and #v6.x.x
?The text was updated successfully, but these errors were encountered: