tags:

views:

42

answers:

2
return 0['toString']['length'];

why does it return 1

+2  A: 

Because the length of the string "0" is 1 character?

romaintaz
He's not calling the `toString()` method, though, so the length property is for the method.
Reinis I.
Yes, in fact my answer was not good, just a try ;) But this is a strange syntax used here (anyway, Javascript is just strance)
romaintaz
+8  A: 

1000['toString'] gives you the function object Number.prototype.toString, and in JS, function objects have a property called length which returns the number of arguments the function takes. In this case is 1 because Number.prototype.toString receives a radix argument.

alert(Number.prototype.toString.length) // 1

References:

Ionuț G. Stan