From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- .../reference/global_objects/math/sqrt/index.html | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 files/vi/web/javascript/reference/global_objects/math/sqrt/index.html (limited to 'files/vi/web/javascript/reference/global_objects/math/sqrt') diff --git a/files/vi/web/javascript/reference/global_objects/math/sqrt/index.html b/files/vi/web/javascript/reference/global_objects/math/sqrt/index.html new file mode 100644 index 0000000000..cefbcccb04 --- /dev/null +++ b/files/vi/web/javascript/reference/global_objects/math/sqrt/index.html @@ -0,0 +1,101 @@ +--- +title: Math.sqrt() +slug: Web/JavaScript/Reference/Global_Objects/Math/sqrt +tags: + - JavaScript + - Math + - Phương Thức + - Tham khảo + - Toán +translation_of: Web/JavaScript/Reference/Global_Objects/Math/sqrt +--- +
{{JSRef}}
+ +

Hàm Math.sqrt() trả về giá trị căn bậc hai, that is

+ +

x0,Math.sqrt(x)=x=trị tuyệt đối củay0tương ứngy2=x\forall x \geq 0, \mathtt{Math.sqrt(x)} = \sqrt{x} = \text{the unique} \; y \geq 0 \; \text{such that} \; y^2 = x

+ +
{{EmbedInteractiveExample("pages/js/math-sqrt.html")}}
+ + + +

Cú pháp

+ +
Math.sqrt(x)
+ +

Tham số

+ +
+
x
+
Một con số
+
+ +

Giá trị trả về

+ +

Căn bậc hai của số cung cấp. Nếu hàm nhận giá trị, {{jsxref("NaN")}} sẽ bị trả về.

+ +

Mô tả

+ +

Nếu x là con số âm, Math.sqrt() sẽ trả về {{jsxref("NaN")}}.

+ +

Do sqrt() là phương thức tĩnh của Math, ta phải dùng theo cách này Math.sqrt(), thay vì dùng dưới dạng phương thức của đối tượng Math mà bạn tạo ra (Math không phải là một hàm khởi tạo, constructor).

+ +

Ví dụ

+ +

Dùng Math.sqrt()

+ +
Math.sqrt(9); // 3
+Math.sqrt(2); // 1.414213562373095
+
+Math.sqrt(1);  // 1
+Math.sqrt(0);  // 0
+Math.sqrt(-1); // NaN
+Math.sqrt(-0); // -0
+
+ +

Thông số kỹ thuật

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Thông số kỹ thuậtTrạng tháiChú thích
{{SpecName('ES1')}}{{Spec2('ES1')}}Định nghĩa lần đầu. Tích hợp trong JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.8.2.17', 'Math.sqrt')}}{{Spec2('ES5.1')}}
{{SpecName('ES6', '#sec-math.sqrt', 'Math.sqrt')}}{{Spec2('ES6')}}
{{SpecName('ESDraft', '#sec-math.sqrt', 'Math.sqrt')}}{{Spec2('ESDraft')}}
+ +

Tính tương thích trên trình duyệt

+ + + +

{{Compat("javascript.builtins.Math.sqrt")}}

+ +

Xem thêm

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