JavaScript Function valueOf()
Description
The valueOf() method returns the primtive value of a function as a string.
The valueOf() method does not change the original function.
Example
function myFunction() {
return "Hello";
}
let text = myFunction.valueOf();
Try it Yourself »
return "Hello";
}
let text = myFunction.valueOf();
Same as:
let text = myFunction;
Try it Yourself »
Note
The valueOf() method is the default method for JavaScript functions.
It is used internally by JavaScript.
Normally, you will not use it in your code.
Syntax
function.valueOf()
Parameters
NONE
Return Value
Type
Description
String The source code of the function as a string.
Function Methods & Properties
Browser Support
function.valueOf() is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |