String.prototype.toString()

  • Revision slug: JavaScript/Reference/Global_Objects/String/toString
  • Revision title: toString
  • Revision id: 87732
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment 1 words added, 5 words removed

Revision Content

 

Summary

Returns a string representing the specified object.

Method of String
Implemented in JavaScript 1.1
ECMAScript Edition ECMAScript 1st Edition

Syntax

string.toString()

Parameters

None.

Description

The String object overrides the toString method of the Object object; it does not inherit Object.toString. For String objects, the toString method returns a string representation of the object.

Examples

Example: Using toString

The following example displays the string value of a String object:

x = new String("Hello world");
alert(x.toString())      // Displays "Hello world"

See also

Object.toString

 

{{ languages( { "es": "es/Referencia_de_JavaScript_1.5/Objetos_globales/String/toString", "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/String/toString", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/String/toString" } ) }}

Revision Source

<p> </p>
<h3 id="Summary" name="Summary">Summary</h3>
<p>Returns a string representing the specified object.</p>
<table class="standard-table"> <thead> <tr> <th class="header" colspan="2">Method of <a href="/en/JavaScript/Reference/Global_Objects/String"><code>String</code></a></th> </tr> </thead> <tbody> <tr> <td>Implemented in</td> <td>JavaScript 1.1</td> </tr> <tr> <td>ECMAScript Edition</td> <td>ECMAScript 1st Edition</td> </tr> </tbody>
</table> <h3 id="Syntax" name="Syntax">Syntax</h3>
<p><code><em>string</em>.toString()</code></p>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<p>None.</p>
<h3 id="Description" name="Description">Description</h3>
<p>The <code>String</code> object overrides the <code>toString</code> method of the <code><a href="/en/JavaScript/Reference/Global_Objects/Object" title="en/JavaScript/Reference/Global_Objects/Object">Object</a></code> object; it does not inherit <code><a href="/en/JavaScript/Reference/Global_Objects/Object/toString" title="en/JavaScript/Reference/Global_Objects/Object/toString">Object.toString</a></code>. For <code>String</code> objects, the <code>toString</code> method returns a string representation of the object.</p>
<h3 id="Examples" name="Examples">Examples</h3>
<h4 id="Example:_Using_toString" name="Example:_Using_toString">Example: Using <code>toString</code></h4>
<p>The following example displays the string value of a String object:</p>
<pre>x = new String("Hello world");
alert(x.toString())      // Displays "Hello world"
</pre>
<h3 id="See_also" name="See_also">See also</h3>
<p><a href="/en/JavaScript/Reference/Global_Objects/Object/toString" title="en/JavaScript/Reference/Global_Objects/Object/toString">Object.toString</a></p>
<p> </p> <p>{{ languages( { "es": "es/Referencia_de_JavaScript_1.5/Objetos_globales/String/toString", "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/String/toString", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/String/toString" } ) }}</p>
Revert to this revision