There are various methods that go by the name of toString
, each with its own unique behavior. In addition to @xdazz's answer, let's explore how toString
differs in different types:
[].toString.call("abc"); //Array
Even here, the result is not "abc"
.
document.querySelectorAll("*").toString.call("abc") //Node List
Again, this does not give us "abc"
.
(2).prototype.toString.call("abc") //Number
An error occurs, and it's worth noting that toString
in Number can also receive a radix argument.
In conclusion, these methods all have distinct behaviors. Due to its peculiar nature as an Object
, even window
has a different implementation of toString
compared to String
's.