Skip to content

Latest commit

 

History

History
68 lines (57 loc) · 1.63 KB

File metadata and controls

68 lines (57 loc) · 1.63 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
Math.abs Function (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
abs
JavaScript
TypeScript
DHTML
absolute values, calculating
absolute values
numeric expressions
abs method
9af4b5b8-de77-47bb-bb59-abdde371e4c3
18
mikejo5000
mikejo
ghogen

Math.abs Function (JavaScript)

Returns the absolute value of a number (the value without regard to whether it is positive or negative). For example, the absolute value of -5 is the same as the absolute value of 5.

Syntax

Math.abs(number)  

Parameters

The required number argument is a numeric expression for which the absolute value is needed.

Return Value

The absolute value of the number argument.

Example

The following example illustrates the use of the abs function.

var s;  
var v1 = Math.abs(6);  
var v2 = Math.abs(-6);  
if (v1 == v2) {  
    document.write("Absolute values are the same.");  
}  
else {  
document.write("Absolute values are different.");  
}  
  
// Output: Absolute values are the same.  
  

Requirements

[!INCLUDEjsv1]

Applies To: Math Object

See Also

Math Object