Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why 123['toString'].length returns 1?

console.log(123['toString'].length);

why this code returns value: 1 ?

Any good explanation?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Because in javascript the length of a function is the number of named arguments it accepts.

Your 123['toString'] returns the toString method of numbers which accepts a radix parameter (see Number.prototype.toString), so that is what 1 is for.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading