alter
alter

Reputation: 4436

javascript length property

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

why does it return 1

Upvotes: 0

Views: 310

Answers (2)

Ionuț G. Stan
Ionuț G. Stan

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

Romain Linsolas
Romain Linsolas

Reputation: 81667

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

Upvotes: 2

Related Questions