© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Russell Reyes
Cat Coder
Peter Scheler
JS enthusiast
This results from the two meanings of ".":
In the case of 2.toString(), it looks for an object named "2" (and numeric identifiers are forbidden). The Number '2' is still not evaluated.
2.toString()
In the case of 2..toString(), it evaluates "2." (same as "2.0") to the Number object, which then accesses the toString method.
2..toString()
toString
It is the same as (2).toString().
(2).toString()
Peter Scheler
JS enthusiast
This results from the two meanings of ".":
In the case of
2.toString(), it looks for an object named "2" (and numeric identifiers are forbidden). The Number '2' is still not evaluated.In the case of
2..toString(), it evaluates "2." (same as "2.0") to the Number object, which then accesses thetoStringmethod.It is the same as
(2).toString().