--- title: String.prototype.valueOf() slug: Web/JavaScript/Reference/Global_Objects/String/valueOf translation_of: Web/JavaScript/Reference/Global_Objects/String/valueOf ---
valueOf()
方法返回 {{jsxref("String")}} 对象的原始值
str.valueOf()
A string representing the primitive value of a given {{jsxref("String")}} object.
The valueOf()
method of {{jsxref("String")}} returns the primitive value of a {{jsxref("String")}} object as a string data type. This value is equivalent to {{jsxref("String.prototype.toString()")}}.
此方法通常由JavaScript在内部调用,而不是在代码中显式调用。
valueOf()
var x = new String('Hello world'); console.log(x.valueOf()); // Displays 'Hello world'
规范 |
---|
{{SpecName('ESDraft', '#sec-string.prototype.valueof', 'String.prototype.valueOf')}} |
{{Compat("javascript.builtins.String.valueOf")}}