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 498421 of uneval()

  • Revision slug: Web/JavaScript/Reference/Global_Objects/uneval
  • Revision title: uneval()
  • Revision id: 498421
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment cleanup
Tags: 

Revision Content

{{JSObjectsQLAlpha()}} {{Non-standard_header}}

Summary

The uneval() method creates an string representation of the source code of an Object.

Syntax

uneval(object)

Parameters

object
A JavaScript expression or statement.
Note: You won't get a valid JSON representation of your Object.

Description

uneval() is a top-level function and is not associated with any object.

Examples

var a = 1;
uneval(a); // returns a String containing 1

var b = "1";
uneval(b) // returns a String containing "1"

uneval(function foo(){}); // returns "(function foo(){})"


var a = uneval(function foo(){return 'hi'});
var foo = eval(a);
foo(); // returns "hi"

Specifications

Not part of any specifications.

Browser compatibility

{{ CompatibilityTable() }}

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

See also

  • {{jsxref("Global_Objects/eval", "eval()")}}
  • {{jsxref("JSON.stringify")}}
  • {{jsxref("JSON.parse")}}
  • {{jsxref("Object.toSource")}}

Revision Source

<div>
 {{JSObjectsQLAlpha()}} {{Non-standard_header}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code><strong>uneval()</strong></code> method creates an string representation of the source code of an Object.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
uneval(<var>object</var>)</pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<dl>
 <dt>
  <code>object</code></dt>
 <dd>
  A JavaScript expression or statement.</dd>
</dl>
<div class="note">
 <strong>Note:</strong> You won't get a valid JSON representation of your Object.</div>
<h2 id="Description" name="Description">Description</h2>
<p><code>uneval()</code> is a top-level function and is not associated with any object.</p>
<h2>Examples</h2>
<pre class="brush:js">
var a = 1;
uneval(a); // returns a String containing 1

var b = "1";
uneval(b) // returns a String containing "1"

uneval(function foo(){}); // returns "(function foo(){})"


var a = uneval(function foo(){return 'hi'});
var foo = eval(a);
foo(); // returns "hi"
</pre>
<h2 name="See_also">Specifications</h2>
<p>Not part of any specifications.</p>
<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>{{ CompatNo() }}</td>
    <td>{{ CompatVersionUnknown() }}</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>{{ CompatVersionUnknown() }}</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("Global_Objects/eval", "eval()")}}</li>
 <li>{{jsxref("JSON.stringify")}}</li>
 <li>{{jsxref("JSON.parse")}}</li>
 <li>{{jsxref("Object.toSource")}}</li>
</ul>
Revert to this revision