Reputation: 4436
return 0['toString']['length'];
why does it return 1
Upvotes: 0
Views: 310
Reputation: 179199
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:
Upvotes: 9