String.prototype.toString()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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® 2025 Language Specification
# sec-string.prototype.tostring
Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
toString

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Veja também