A valueOf() function used to converts string object to primitive value of string. It does not change the original string of string object. This function is the default function for JavaScript strings object which is used internally by JavaScript.
1 <string_object>.valueOf()
string_object : A string object which value needs to be extracted
return : It returns string value from string object
1
2 let str = "Hello world !";
3 str.valueOf();
4
5
6 let str = new String("Hello world");
7 str.valueOf();
In the above example, we have define string literal and retrieving value of string using valueOf() function. In the second example, we have define string object using new keyword and retrieving value of string object using valueOf() function.
Related options for your search