From bf8e099b9c8b3c60d60b3712b4fc97b052c39887 Mon Sep 17 00:00:00 2001 From: julieng Date: Tue, 3 Aug 2021 08:03:23 +0200 Subject: convert content to md --- .../reference/global_objects/math/abs/index.md | 107 ++++++++------------- 1 file changed, 41 insertions(+), 66 deletions(-) (limited to 'files/fr/web/javascript/reference/global_objects/math/abs/index.md') diff --git a/files/fr/web/javascript/reference/global_objects/math/abs/index.md b/files/fr/web/javascript/reference/global_objects/math/abs/index.md index c632d426db..6a1a7d758d 100644 --- a/files/fr/web/javascript/reference/global_objects/math/abs/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/abs/index.md @@ -9,40 +9,39 @@ tags: translation_of: Web/JavaScript/Reference/Global_Objects/Math/abs original_slug: Web/JavaScript/Reference/Objets_globaux/Math/abs --- -
{{JSRef}}
+{{JSRef}} -

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

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

+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")}}
+{{EmbedInteractiveExample("pages/js/math-abs.html")}} -

Syntaxe

+## Syntaxe -
Math.abs(x);
+ Math.abs(x); -

Paramètres

+### Paramètres -
-
x
-
Un nombre.
-
+- `x` + - : Un nombre. -

Valeur absolue

+### Valeur absolue -

La valeur absolue du nombre passé en argument.

+La valeur absolue du nombre passé en argument. -

Description

+## Description -

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

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

Exemples

+## Exemples -

Utiliser Math.abs()

+### 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.

+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
+```js
+Math.abs('-1');     // 1
 Math.abs(-2);       // 2
 Math.abs(null);     // 0
 Math.abs('');       // 0
@@ -51,50 +50,26 @@ 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

- - +Math.abs(); // NaN +``` + +## 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.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 + +- {{jsxref("Math.ceil()")}} +- {{jsxref("Math.floor()")}} +- {{jsxref("Math.round()")}} +- {{jsxref("Math.sign()")}} +- {{jsxref("Math.trunc()")}} -- cgit v1.2.3-54-g00ecf