toString()

The toString() method is used to return the contents of the string object. If it is invoked with the String object, the returned value will be the object type or name of the constructor which created the object. The example best illustrates the use of the toString() method.

syntax:

string.toString()

String.toString()

EXAMPLE

var theString = new String("This is the string text");

document.write(theString.toString() + "
");

document.write(String.toString() );

The example first creates a new String object, which is then loaded with the above chunk of text. The document.write statement following then writes the contents of theString to the screen referencing the theString object with the toString() method. The next document.write statement then utilizes the use of the toString() method with the String Core Object. The results are then written to the screen, and should look like the following:



This is the string text

function String() { [native code] }