String.prototype.toString()

概述

toString() 方法返回指定对象的字符串形式。

语法

str.toString()

返回值

一个表示调用对象的字符串。

描述

String 对象覆盖了String.prototype.valueOf() 方法返回值一样。

示例

例子:使用 toString

下例输出一个字符串对象(String object)的字符串值:

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

alert(x.toString())      // 输出 "Hello world"

规范

Specification Status Comment
ECMAScript 3rd Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
String.prototype.toString
Standard
ECMAScript 2015 (6th Edition, ECMA-262)
String.prototype.toString
Standard
ECMAScript Latest Draft (ECMA-262)
String.prototype.toString
Draft

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

相关链接