String.prototype.toString()

O método toString() retorna uma string representando o objeto especificado.

Sintaxe

str.toString()

Descrição

O objeto String substitui o método toString() do objeto Object. Ele não herda Object.prototype.toString(). Para objetos String, o método toString() retorna uma representação de string do objeto e é o mesmo que o método String.prototype.valueOf().

Exemplos

Usando toString()

O exemplo a seguir exibe o valor string de um objeto String:

js
var x = new String("Hello world");

console.log(x.toString()); // retorna 'Hello world'

Especificações

Specification
ECMAScript Language Specification
# sec-string.prototype.tostring

BCD tables only load in the browser

Veja também