String.prototype.valueOf()
valueOf()
方法返回 String
对象的原始值
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
语法
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'
规范
浏览器兼容性
BCD tables only load in the browser
此页中的兼容性表是从结构化数据生成的。如果你想对数据有所贡献,请查看https://github.com/mdn/browser-compat-data并向我们发送请求。