Open In App

JavaScript String valueOf() Method

Last Updated : 18 Jul, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

JavaScript String valueOf() method is an inbuilt method in JavaScript that is used to return the value of the given string. The valueOf() method in JavaScript returns the primitive value of a string. It does not modify the original string. This method can also be used to convert a string object into a string.

Syntax: 

string.valueOf()

Parameters: It does not accept any parameter.

Return Values: It returns a string that represents the value of the given string object.

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

Example 1: Here is the basic example if a string.valueOf() method.

javascript




let a = new String("GeeksforGeeks");
console.log(a.valueOf());


Output: 

GeeksforGeeks

Example 2: Another example of the above-explained-method.

javascript




// Taking a string as input and printing it
// with the help of string.valueOf() method
let a = new String("GeeksforGeeks");
console.log(a.valueOf());


Output: 

GeeksforGeeks

Example 3: In this example, using the valueOf() method to obtain their primitive string values.

javascript




// Taking a string as input and printing it
// with the help of string.valueOf() method
let a = new String("Geeks");
let b = new String("for");
let c = new String("Geeks");
console.log(a.valueOf(), b.valueOf(), c.valueOf());


Output: 

GeeksforGeeks

We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article.

Supported Browser:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 4 and above
  • Opera 3 and above
  • Safari 1 and above


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads