JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)
What is the purpose of uneval
The uneval() is an builtin function which is used to create a string representation of the source code of an Object. It is a top-level function and is not associated with any object. Let's see the below example to know more about it's functionality,
javascript
var a = 1;
uneval(a); // returns a String containing 1
uneval(function user() {}); // returns "(function user(){})"
The uneval() function has been deprecated. It is recommended to use toString() for functions and JSON.stringify() for other cases.
javascript
function user() {}
console.log(user.toString()); // returns "(function user(){})"