A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Math/abs below:

Math.abs() - JavaScript | MDN

Math.abs()

Baseline Widely available

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

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

Exemple interactif
function difference(a, b) {
  return Math.abs(a - b);
}

console.log(difference(3, 5));
// Expected output: 2

console.log(difference(5, 3));
// Expected output: 2

console.log(difference(1.23456, 7.89012));
// Expected output: 6.6555599999999995
Syntaxe Paramètres 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 undefined, la valeur retournée sera NaN. Si elle est utilisée avec 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 Compatibilité des navigateurs Voir aussi

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4