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

  • Revision slug: Web/JavaScript/Reference/Global_Objects/uneval
  • Revision title: uneval
  • Revision id: 485193
  • Created:
  • Creator: MatthewKastor
  • Is current revision? No
  • Comment example shows how to use uneval instead of a crappy nonfunctional example.
Tags: 

Revision Content

{{Non-standard_header}}

Summary

Creates an string representation of the source code of an Object

Core Global Method
Implemented in JavaScript ?
ECMAScript Edition ECMAScript ?

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.

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"

See also

Revision Source

<div>
 {{Non-standard_header}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>Creates an string representation of the source code of an Object</p>
<table class="standard-table">
 <thead>
  <tr>
   <th class="header" colspan="2">Core Global Method</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>Implemented in</td>
   <td>JavaScript ?</td>
  </tr>
  <tr>
   <td>ECMAScript Edition</td>
   <td>ECMAScript ?</td>
  </tr>
 </tbody>
</table>
<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>
<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 id="See_also" name="See_also">See also</h2>
<ul>
 <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/eval"><code>eval()</code></a></li>
 <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify"><code>JSON.stringify</code></a></li>
 <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/JSON/parse"><code>JSON.parse</code></a></li>
 <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/toSource"><code>Object.toSource</code></a></li>
</ul>
Revert to this revision