From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/string/valueof/index.html | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/string/valueof/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/string/valueof') diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/valueof/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/valueof/index.html new file mode 100644 index 0000000000..7697c1074d --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/string/valueof/index.html @@ -0,0 +1,58 @@ +--- +title: String.prototype.valueOf() +slug: Web/JavaScript/Reference/Global_Objects/String/valueOf +translation_of: Web/JavaScript/Reference/Global_Objects/String/valueOf +--- +
{{JSRef}}
+ +

valueOf() 方法返回  {{jsxref("String")}}  对象的原始值

+ +
{{EmbedInteractiveExample("pages/js/string-valueof.html")}}
+ +

语法

+ +
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")}}

+ +

参见

+ + -- cgit v1.2.3-54-g00ecf