Apply your JS skills to key Mozilla projects as an MDN Fellow! http://mzl.la/MDNFellowship

mozilla

Compare Revisions

Object.prototype.toString()

Change Revisions

Revision 417963:

Revision 417963 by Sheppy on

Revision 494547:

Revision 494547 by fscholz on

Title:
Object.toString
Object.prototype.toString()
Slug:
Web/JavaScript/Reference/Global_Objects/Object/toString
Web/JavaScript/Reference/Global_Objects/Object/toString
Tags:
"String Methods", "JavaScript Reference", "JavaScript"
"JavaScript", "Object", "Method", "Prototype"
Content:

Revision 417963
Revision 494547
nn7    <div>
8      {{JSRef("Global_Objects", "Object")}}
9    </div>
n11      Returns a string representing the object.n14      The <code><strong>toString()</strong></code> method returns
 > a string representing object.
n13    <table class="standard-table">n
14      <thead>
15        <tr>
16          <th class="header" colspan="2">
17            Method of <a href="/en-US/docs/JavaScript/Reference/G
>lobal_Objects/Object" title="JavaScript/Reference/Global_Objects/ 
>Object"><code>Object</code></a> 
18          </th>
19        </tr>
20      </thead>
21      <tbody>
22        <tr>
23          <td>
24            Implemented in
25          </td>
26          <td>
27            JavaScript 1.0
28          </td>
29        </tr>
30        <tr>
31          <td>
32            ECMAScript Edition
33          </td>
34          <td>
35            ECMAScript 1st Edition
36          </td>
37        </tr>
38      </tbody>
39    </table>
n44<code><em>object</em>.toString()</code>n20<code><em>obj</em>.toString()</code>
n57      Starting in JavaScript 1.8.5 <code>toString()</code> calledn33      Starting in JavaScript 1.8.5 <code>toString()</code> called
> on <code>null</code> returns <code>[object <em>Null</em>]</code>> on <code>null</code> returns <code>[object <em>Null</em>]</code>
>, and <code>undefined</code> returns <code>[object <em>Undefined<>, and <code>undefined</code> returns <code>[object <em>Undefined<
>/em>]</code>, as defined in the 5th Edition of ECMAScript and a s>/em>]</code>, as defined in the 5th Edition of ECMAScript and a s
>ubsequent Errata. See <a href="/en-US/docs/JavaScript/Reference/G>ubsequent Errata. See {{anch("Using toString to detect object typ
>lobal_Objects/Object/toString#Using_toString_to_detect_object_typ>e")}}.
>e" title="JavaScript/Reference/Global Objects/Object/toString#Usi 
>ng toString to detect object type">Using toString to detect objec 
>t type</a>. 
n84    <pre>n60    <pre class="brush: js">
nn95    <h2 id="Specifications">
96      Specifications
97    </h2>
98    <table class="standard-table">
99      <tbody>
100        <tr>
101          <th scope="col">
102            Specification
103          </th>
104          <th scope="col">
105            Status
106          </th>
107          <th scope="col">
108            Comment
109          </th>
110        </tr>
111        <tr>
112          <td>
113            ECMAScript 1st Edition. Implemented in JavaScript 1.0
 >.
114          </td>
115          <td>
116            Standard
117          </td>
118          <td>
119            Initial definition.
120          </td>
121        </tr>
122        <tr>
123          <td>
124            {{SpecName('ES5.1', '#sec-15.2.4.2', 'Function.protot
 >ype.toString')}}
125          </td>
126          <td>
127            {{Spec2('ES5.1')}}
128          </td>
129          <td>
130            Call on <code>null</code> returns <code>[object <em>N
 >ull</em>]</code>, and <code>undefined</code> returns <code>[objec
 >t <em>Undefined</em>]</code>
131          </td>
132        </tr>
133        <tr>
134          <td>
135            {{SpecName('ES6', '#sec-object.prototype.tostring', '
 >Object.prototype.toString')}}
136          </td>
137          <td>
138            {{Spec2('ES6')}}
139          </td>
140          <td>
141            &nbsp;
142          </td>
143        </tr>
144      </tbody>
145    </table>
146    <h2 id="Browser_compatibility">
147      Browser compatibility
148    </h2>
149    <p>
150      {{ CompatibilityTable() }}
151    </p>
152    <div id="compat-desktop">
153      <table class="compat-table">
154        <tbody>
155          <tr>
156            <th>
157              Feature
158            </th>
159            <th>
160              Chrome
161            </th>
162            <th>
163              Firefox (Gecko)
164            </th>
165            <th>
166              Internet Explorer
167            </th>
168            <th>
169              Opera
170            </th>
171            <th>
172              Safari
173            </th>
174          </tr>
175          <tr>
176            <td>
177              Basic support
178            </td>
179            <td>
180              {{ CompatVersionUnknown() }}
181            </td>
182            <td>
183              {{ CompatVersionUnknown() }}
184            </td>
185            <td>
186              {{ CompatVersionUnknown() }}
187            </td>
188            <td>
189              {{ CompatVersionUnknown() }}
190            </td>
191            <td>
192              {{ CompatVersionUnknown() }}
193            </td>
194          </tr>
195        </tbody>
196      </table>
197    </div>
198    <div id="compat-mobile">
199      <table class="compat-table">
200        <tbody>
201          <tr>
202            <th>
203              Feature
204            </th>
205            <th>
206              Android
207            </th>
208            <th>
209              Chrome for Android
210            </th>
211            <th>
212              Firefox Mobile (Gecko)
213            </th>
214            <th>
215              IE Mobile
216            </th>
217            <th>
218              Opera Mobile
219            </th>
220            <th>
221              Safari Mobile
222            </th>
223          </tr>
224          <tr>
225            <td>
226              Basic support
227            </td>
228            <td>
229              {{ CompatVersionUnknown() }}
230            </td>
231            <td>
232              {{ CompatVersionUnknown() }}
233            </td>
234            <td>
235              {{ CompatVersionUnknown() }}
236            </td>
237            <td>
238              {{ CompatVersionUnknown() }}
239            </td>
240            <td>
241              {{ CompatVersionUnknown() }}
242            </td>
243            <td>
244              {{ CompatVersionUnknown() }}
245            </td>
246          </tr>
247        </tbody>
248      </table>
249    </div>
n123      <li>n254      <li>{{jsxref("Object.prototype.toSource()")}}
124        <a href="/en-US/docs/JavaScript/Reference/Global_Objects/
>Object/toSource" title="JavaScript/Reference/Global_Objects/Objec 
>t/toSource">Object.toSource</a> 
t126      <li>t256      <li>{{jsxref("Object.prototype.valueOf()")}}
127        <a href="/en-US/docs/JavaScript/Reference/Global_Objects/
>Object/valueOf" title="JavaScript/Reference/Global_Objects/Object 
>/valueOf">Object.valueOf</a> 

Back to History