AppDividend
Latest Code Tutorials

Javascript String valueOf Tutorial With Example | String.prototype.valueof()

0

Javascript String valueOf Example | String.prototype.valueof() Tutorial is today’s topic. The string.valueOf() is the inbuilt function in JavaScript which is used to return a value of the given string. JS valueOf() method returns a primitive value of the String object. The valueof() in JS method is usually called automatically by JavaScript behind the scenes, and not explicitly in code.

Javascript String valueOf Tutorial

The string represents the primitive value of a given String object. The JS valueof() returns the primitive value of a String object. See the following syntax of Javascript valueOf() function.

#Syntax

string.valueOf()

The function does not take any parameters.

See the following example.

// app.js

let data = "Krunal Lathiya";
let res = data.valueOf();
console.log(res);

See the output.

Javascript String valueOf Tutorial

 

The valueOf() method of String returns a primitive value of the String object as a string data type. This value is equivalent to String.proptotype.toString method.

Let’s see one more example to print the primitive value of the string object.

// app.js

let data = new String('Ankit Lathiya');
let res = data.valueOf();
console.log(res);

See the following output.

String.prototype.valueof()

 

The Javascript valueOf() method does not change the value of the original string.

Finally, Javascript String valueOf Tutorial With Example | String.prototype.valueof() is over.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.