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
:
var x = new String("Hello world");
console.log(x.toString()); // retorna 'Hello world'
Especificações
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype.tostring |
Navegadores compatíveis
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toString |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support