Revision 487405 of Boolean.prototype.toString()

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Boolean/toString
  • Revision title: Boolean.prototype.toString()
  • Revision id: 487405
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment cleanup

Revision Content

{{JSRef("Global_Objects", "Boolean")}}

Summary

The toSource() method returns a string representing the specified Boolean object.

Syntax

bool.toString()

Parameters

None.

Description

The {{jsxref("Global_Objects/Boolean", "Boolean")}} object overrides the toString method of the {{jsxref("Global_Objects/Object", "Object")}} object; it does not inherit {{jsxref("Object.prototype.toString()")}}. For Boolean objects, the toString method returns a string representation of the object.

JavaScript calls the toString method automatically when a Boolean is to be represented as a text value or when a Boolean is referred to in a string concatenation.

For Boolean objects and values, the built-in toString method returns the string "true" or "false" depending on the value of the boolean object.

Examples

Example: Using toString

In the following code, flag.toString returns "true":

var flag = new Boolean(true)
var myVar = flag.toString()

Specifications

Specification Status Comment
ECMAScript 1st Edition. Implemented in JavaScript 1.1 Standard Initial definition.
{{SpecName('ES5.1', '#sec-15.6.4.2', 'Boolean.prototype.toString')}} {{Spec2('ES5.1')}}  
{{SpecName('ES6', '#sec-boolean.prototype.tostring', 'Date.prototype.toString')}} {{Spec2('ES6')}}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}

See also

  • {{jsxref("Object.prototype.toString()")}}

Revision Source

<div>
 {{JSRef("Global_Objects", "Boolean")}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code><strong>toSource()</strong></code> method returns a string representing the specified Boolean object.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<var>bool</var>.toString()</pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<p>None.</p>
<h2 id="Description" name="Description">Description</h2>
<p>The {{jsxref("Global_Objects/Boolean", "Boolean")}} object overrides the <code>toString</code> method of the {{jsxref("Global_Objects/Object", "Object")}} object; it does not inherit {{jsxref("Object.prototype.toString()")}}. For Boolean objects, the <code>toString</code> method returns a string representation of the object.</p>
<p>JavaScript calls the <code>toString</code> method automatically when a Boolean is to be represented as a text value or when a Boolean is referred to in a string concatenation.</p>
<p>For Boolean objects and values, the built-in <code>toString</code> method returns the string "<code>true</code>" or "<code>false</code>" depending on the value of the boolean object.</p>
<h2>Examples</h2>
<h3>Example: Using <code>toString</code></h3>
<p>In the following code, <code>flag.toString</code> returns "<code>true</code>":</p>
<pre class="brush: js">
var flag = new Boolean(true)
var myVar = flag.toString()
</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>ECMAScript 1st Edition. Implemented in JavaScript 1.1</td>
   <td>Standard</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.6.4.2', 'Boolean.prototype.toString')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-boolean.prototype.tostring', 'Date.prototype.toString')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Chrome for Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_Also" name="See_Also">See also</h2>
<ul>
 <li>{{jsxref("Object.prototype.toString()")}}</li>
</ul>
Revert to this revision