David said:
I'm new to the almighty comp.lang.javascript... sorry if this is a
dumbass post, but I stumbled across this JS quirk today:
isNaN([6]) is false
so an array is a number - who knew?
Erm, that means that array is Not a Number.
You mean it (the false results) means that an (or rather this) array
is not Not a Number.
But most arrays would return true. The issue here is that the - isNaN
- function applies the internal - ToNumber - function to the array,
which calls the - ToPrimative - function with the hint 'Number', that
calls the array's internal [[DefaultValue]] method with the hint
'Number', which starts off trying to call the array's -valueOf -
method, but because the valueOf - methods of arrays are inherited from
Object.prototype.valueOf it is the version that return the object
itself, so [[DefaultValue]] goes on to call the array's - toString -
method, that method returns the string "6" from the one element array,
and the string "6", when received by the - ToNumber - function,
happily type-converts to a non-NaN number.