Back

str.valueOf()

str.valueOf()

The valueOf() method returns the primitive value of a String object.

Syntax

str.valueOf()

Description

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

This method is usually called internally by JavaScript and not explicitly in code.

Examples

Using valueOf()

var x = new String('Hello world');
console.log(x.valueOf()); // Displays 'Hello world'

  Created by Mozilla Contributors, license: CC-BY-SA 2.5