Java Reference
In-Depth Information
The
toString()
method is used by a number of built-in functions in the background. It
can be used without fear of causing an error because
every
object has the method, as it's
inherited from the
Object
prototype object.
One example of a function that uses the
toString()
method is the
alert()
. If an
object is given as an argument to the
alert
function that isn't a string, it will call
toString()
on that object in the background and display the returned string. For ex-
ample, the code:
alert([1,2,3]);
will display an alert dialog like the one shown in
Figure 12.1
.
Figure 12.1.
alert()
uses
toString()
