--- title: Math.sqrt() slug: Web/JavaScript/Reference/Global_Objects/Math/sqrt tags: - JavaScript - Math - Méthode - Reference translation_of: Web/JavaScript/Reference/Global_Objects/Math/sqrt original_slug: Web/JavaScript/Reference/Objets_globaux/Math/sqrt --- {{JSRef}} La fonction **`Math.sqrt()`** renvoie la racine carrée d'un nombre. Cette fonction est définie par : x0,Math.sqrt(x)=x=l'uniquey0tel quey2=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")}} ## Syntaxe Math.sqrt(x) ### Paramètres - `x` - : Un nombre. ### Valeur de retour La racine carrée du nombre passé en argument. Si le nombre fourni est négatif, c'est {{jsxref("NaN")}} qui sera renvoyé. ## Description Si la valeur de `x` est négative, `sqrt` renverra {{jsxref("NaN")}}. `sqrt()` est une méthode statique de `Math`, elle doit être utilisée avec la syntaxe `Math.sqrt()`, elle ne doit pas être appelée comme méthode d'un autre objet qui aurait été créé (`Math` n'est pas un constructeur). ## Exemples ```js 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 ``` ## Spécifications | Spécification | État | Commentaires | | ------------------------------------------------------------------------ | ---------------------------- | ----------------------------------------------------- | | {{SpecName('ES1')}} | {{Spec2('ES1')}} | Définition initiale. Implémentée avec 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')}} |   | ## Compatibilité des navigateurs {{Compat("javascript.builtins.Math.sqrt")}} ## Voir aussi - {{jsxref("Math.cbrt()")}} - {{jsxref("Math.exp()")}} - {{jsxref("Math.log()")}} - {{jsxref("Math.pow()")}}