Open In App

JavaScript uneval() Function

Last Updated : 24 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The uneval() is an inbuilt function in Javascript that is used to create a string representation of the source code of an Object. 

Syntax:

uneval(object)

Note: This function has been DEPRECATED and is no longer recommended.

Parameters: It accepts an object which may be a JavaScript expression or statement. 

Return Value: It returns a string that represents the source code of the given Object.

JavaScript examples to show the working of this function:

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

javascript




let obj = 2;
console.log(eval(obj));


Output:

2

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

javascript




let obj = '2';
console.log(uneval(obj));


Output:

"2"

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

javascript




let obj = uneval(function func() { return 'Geeksforgeeks'; });
let func1 = eval(obj);
console.log(func1());


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 the Firefox web browser.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads