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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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

I like to do coding in C++C and java programming languages HTML and CSS always intersts me Sharing knowleged is the best way according to me to increase ones knwoledge

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.