Math.abs

abs — Returns the absolute value of a number.

Description

Math.abs(number number)

Parameters

Name Description Type Default Optional
number number No

Examples

Example #1 – abs example
console.log(Math.abs(4)); // 4 console.log(Math.abs(-1.2)); // 1.2 console.log(Math.abs(null)); // 0 console.log(Math.abs(true)); // 1 console.log(Math.abs(-Infinity)); // Infinity console.log(Math.abs('')); // 0 console.log(Math.abs('String')); // NaN

External references