JavaScript string.valueOf() Method

Below is the example of the string.valueOf() Method.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script>
        var a = new String("GeeksforGeeks");
        document.write(a.valueOf());
    </script>

    chevron_right

    
    

  • Output:
    GeeksforGeeks

The string.valueOf() is an inbuilt method in JavaScript which is used to return the value of the given string.

Syntax:

string.valueOf()

Parameters: It does not accept any parameter.

Return Values: It returns a string which represent the value of the given string object.



JavaScript code to show the working of string.valueOf() method:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
    // Taking a string as input and printing it
    // with the help of string.valueOf() function
    var a = new String("GeeksforGeeks");
    document.write(a.valueOf());
</script>

chevron_right


Output:

GeeksforGeeks

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
    // Taking a string as input and printing it
    // with the help of string.valueOf() function
    var a = new String("Geeks");
    var b = new String("for");
    var c = new String("Geeks");
    document.write(a.valueOf(),b.valueOf(),c.valueOf());
</script>

chevron_right


Output:

GeeksforGeeks

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.