Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 704573 of String.prototype.quote()

  • Revision slug: Web/JavaScript/Reference/Global_Objects/String/quote
  • Revision title: String.prototype.quote()
  • Revision id: 704573
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment

Revision Content

{{obsolete_header("37")}}
{{JSRef("Global_Objects", "String")}} {{non-standard_header}}

Summary

The non-standard quote() method returns a copy of the string, replacing various special characters in the string with their escape sequences and wrapping the result in double-quotes (").

Syntax

str.quote()

Examples

In the table below the quote() method replaces any special characters and wraps the strings in double-quotes. Also note the third column where a wrapped {{jsxref("Global_Objects/eval", "eval()")}} evaluates the escape sequences again.

str str.quote() eval(str.quote())
Hello world! "Hello world!" Hello world!
Hello
world!
"Hello\n\tworld!" Hello
world!
" \ — ' "\" \\ \u2014 '" " \ — '

Specifications

Not part of any standard. Implemented in JavaScript 1.3.

Browser compatibility

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

See also

  • {{jsxref("JSON.stringify()")}}

Revision Source

<div>
 {{obsolete_header("37")}}</div>
<div>
 {{JSRef("Global_Objects", "String")}} {{non-standard_header}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The non-standard <strong><code>quote()</code></strong> method returns a copy of the string, replacing various special characters in the string with their escape sequences and wrapping the result in double-quotes (<code>"</code>).</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<code><var>str</var>.quote()</code></pre>
<h2 id="Examples" name="Examples">Examples</h2>
<p>In the table below the <code>quote()</code> method replaces any special characters and wraps the strings in double-quotes. Also note the third column where a wrapped {{jsxref("Global_Objects/eval", "eval()")}} evaluates the escape sequences again.</p>
<table class="fullwidth-table">
 <thead>
  <tr>
   <th class="header" scope="col"><code>str</code></th>
   <th class="header" scope="col"><code>str.quote()</code></th>
   <th class="header" scope="col"><code>eval(str.quote())</code></th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><code>Hello world!</code></td>
   <td><code>"Hello world!"</code></td>
   <td><code>Hello world!</code></td>
  </tr>
  <tr>
   <td><code style="white-space: pre;">Hello<br />
    world!</code></td>
   <td><code>"Hello\n\tworld!"</code></td>
   <td><code style="white-space: pre;">Hello<br />
    world!</code></td>
  </tr>
  <tr>
   <td><code>" \ — '</code></td>
   <td><code>"\" \\ \u2014 '"</code></td>
   <td><code>" \ — '</code></td>
  </tr>
 </tbody>
</table>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<p>Not part of any standard. Implemented in JavaScript 1.3.</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
 {{CompatibilityTable}}</div>
<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>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</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>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
 <li>{{jsxref("JSON.stringify()")}}</li>
</ul>
Revert to this revision