I'm struggling to understand why this examples below end up with this kind of results.
String([,,,]); // ',,' why?
Number([8,8]); // NaN why?
please explain with details if possible
I'm struggling to understand why this examples below end up with this kind of results.
String([,,,]); // ',,' why?
Number([8,8]); // NaN why?
please explain with details if possible
Note that String
calls the toString
method on the object, which, for arrays, is equivalent to calling Array#join
.
String([,,,]);
[,,,]
is an array with 3 empty elements. [,,,].join()
will then put two commas as separators between the empty elements, resulting in ",,"
.
Number([8,8]);
[8,8].join()
returns "8,8"
, which cannot be parsed as a Number
, so it produces NaN
.