Basically, this is because:
new Error().toString()
gives "Error"
andparseInt("Error", 16)
gives 14
(because there 0xE
is 14
, and the parser stops at r
).
On the other hand, it new Array()
does not cause the same behavior, because the toString()
array object method returns the contents of the array, separated by commas, and not the class name. Consequently, new Array().toString()
gives an empty string, and parseInt()
subsequently gives NaN
.
source
share