Tutorialspoint.dev

JavaScript | uneval() with Examples

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.

<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.



This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter