15.8.2.1 Math.abs(x)

2010-07-11

number Math.abs(x:number|mixed)

Return x with positive sign but same number otherwise.

Code: (Meta Ecma)
Math.abs = function(x){
x = ToNumber(x);
if (isNaN(x)) return NaN;
if (x === -0) return +0;
if (x === -Infinity) return +Infinity;
if (x < 0) return -x;
return x;
}