Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

JavaScript | uneval() with Examples

  • Last Updated : 25 Jul, 2018

The uneval() is an inbuilt function in JavaScript which is used to create a string representation of the source code of an Object.
Syntax:

uneval(object)

Parameters: It accepts an object which may be a JavaScript expression or statement.
Return Value: It returns a string which represents the source code of the given Object.

JavaScript code to show the working of this function:

Code #1:
If the number is passed to the function uneval() then the function will return a string with the value of the object passed.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!




<script>
  
  var obj = 2;
  document.write(eval(obj));
  
</script>

Output:

2

Code #2:
If the char is passed to the function uneval() then the function will return a string with the value of the object passed.






<script>
  
  var obj = '2';
  document.write(uneval(obj));
  
</script>

Output:

"2"

Code #3: If the number is passed to the function uneval() then the function will return a string with the value of the object passed.




<script>
  
  var obj = uneval(function func() { return 'Geeksforgeeks'; });
  var func1 = eval(obj);
  document.write(func1());
  
</script>

Output:

GeeksforGeeks

Difference between eval() and uneval() functions:
The uneval() function returns the source of a given object whereas the eval() function evaluates that source code in a different memory area.
Note: Above codes will run only in Firefox web browser.




My Personal Notes arrow_drop_up
Recommended Articles
Page :