From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../reference/global_objects/math/abs/index.html | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/math/abs/index.html (limited to 'files/fr/web/javascript/reference/global_objects/math/abs') diff --git a/files/fr/web/javascript/reference/global_objects/math/abs/index.html b/files/fr/web/javascript/reference/global_objects/math/abs/index.html new file mode 100644 index 0000000000..925364b1ca --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/math/abs/index.html @@ -0,0 +1,103 @@ +--- +title: Math.abs() +slug: Web/JavaScript/Reference/Objets_globaux/Math/abs +tags: + - JavaScript + - Math + - Méthode + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Math/abs +--- +
{{JSRef}}
+ +

La fonction Math.abs() retourne la valeur absolue d'un nombre, c'est-à-dire

+ +

Math.abs(x)=|x|={xsix0-xsix<0{\mathtt{\operatorname{Math.abs}(x)}} = {|x|} = \begin{cases} x & \text{si} \quad x \geq 0 \\ -x & \text{si} \quad x < 0 \end{cases}

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

Syntaxe

+ +
Math.abs(x);
+ +

Paramètres

+ +
+
x
+
Un nombre.
+
+ +

Valeur absolue

+ +

La valeur absolue du nombre passé en argument.

+ +

Description

+ +

abs est une méthode statique de l'objet Math et doit toujours être utilisée avec la syntaxe Math.abs().

+ +

Exemples

+ +

Utiliser Math.abs()

+ +

Si la méthode est utilisée avec une chaîne de caractères non numérique, avec un tableau à plus d'un élément, sans paramètre ou avec {{jsxref("undefined")}}, la valeur retournée sera {{jsxref("NaN")}}. Si elle est utilisée avec {{jsxref("null")}}, la fonction renverra 0.

+ +
Math.abs('-1');     // 1
+Math.abs(-2);       // 2
+Math.abs(null);     // 0
+Math.abs('');       // 0
+Math.abs([]);       // 0
+Math.abs([2]);      // 2
+Math.abs([1,2]);    // NaN
+Math.abs({});       // NaN
+Math.abs("string"); // NaN
+Math.abs();         // NaN
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES1')}}{{Spec2('ES1')}}Définition initiale. Implémentée avec JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.8.2.1', 'Math.abs')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-math.abs', 'Math.abs')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-math.abs', 'Math.abs')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ + + +

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

+ +

Voir aussi

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