String.valueOf()

JavaScript1.1+, JScript3.0+, ECMAScript1.0+ NES2+, Nav3+, IE4+, Opera3+ Syntax

							string.valueOf()

Description

The valueOf() method returns the primitive value of the object. In terms of an instance of a String object, this method returns the string itself.

Example

In Listing 6.261, an instance of the String object is created. Since the valueOf() method returns the actual value of the string, "Here is some random text" is written to the user's page.

Listing 6.261 Using the valueOf() Method to Return the Value of the String Instance
 <script language="JavaScript1.1"> <!–– Hide // Create an instance of the String object var myString = new String("Here is some random text."); // Write the value of the string to the page. document.write('The ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.