String.prototype.valueOf()

valueOf() 方法返回 String 对象的原始值

尝试一下

语法

str.valueOf()

返回结果

A string representing the primitive value of a given String object.

描述

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

此方法通常由 JavaScript 在内部调用,而不是在代码中显式调用。

示例

使用 valueOf()

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

规范

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

浏览器兼容性

BCD tables only load in the browser

参见