A RetroSearch Logo

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

Search Query:

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

Math.abs() - JavaScript | MDN

Math.abs()

Baseline Widely available

La función Math.abs() retorna el valor absoluto de un número, que es

Math.abs ( x ) = | x | = { x if x > 0 0 if x = 0 - x if x < 0 {\mathtt{\operatorname{Math.abs}(x)}} = {|x|} = \begin{cases} x & \text{if} \quad x \geq 0 \ -x & \text{if} \quad x < 0 \end{cases} Sintaxis Parámetros Valor de retorno

El valor absoluto del número dado.

Descripción

Como abs() es un método estático de Math, deberías siempre usar Math.abs(), en lugar de un método de un objeto Math que crees (Math no es un constructor).

Ejemplos Comportamiento de Math.abs()

Pasando un string no-numérico o una variable undefined/empty retorna NaN. Pasando null retorna 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
Especificaciones Compatibilidad con navegadores Ver también

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