--- title: Math.sqrt() slug: Web/JavaScript/Reference/Global_Objects/Math/sqrt tags: - JavaScript - Math - Method - Reference translation_of: Web/JavaScript/Reference/Global_Objects/Math/sqrt ---
{{JSRef}}

Die Math.sqrt() Funktion gibt die Quadratwurzel einer Zahl zurück. Diese Ist Mathematisch folgendermaßen definiert:

x0,Math.sqrt(x)=x=einy0so dasy2=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")}}

Syntax

Math.sqrt(x)

Parameter

x
Eine Zahl.

Rückgabewert

Die Quadratwurzel der übergebenen Zahl. Wenn der Parameter negativ ist, wird {{jsxref("NaN")}} zurückgegeben.

Beschreibung

Wenn der Wert von x negativ ist, gibt Math.sqrt() {{jsxref("NaN")}} zurück.

Weil sqrt() eine statische Funktion von Math ist, wird es immer als Math.sqrt() eingesetzt, jedoch nicht als Methode eines erzeugten Math Objektes (Math ist kein Konstruktor).

Beispiele

Einsatz von 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

Spezifikationen

Spezifikation Status Kommentar
{{SpecName('ES1')}} {{Spec2('ES1')}} Initiale Definition. Implementiert in 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')}}  

Browserkompatibilität

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

Siehe auch