Home >Web Front-end >Front-end Q&A >How to output absolute value in JavaScript
In JavaScript, the absolute value can be output through the abs method. The syntax is "Math.abs(x)". The parameter x represents a numerical value, and the return value is the absolute value of Number x.
The operating environment of this article: Windows 7 system, javascript1.8.5, Dell G3 computer.
How to output absolute value in JavaScript?
abs() method returns the absolute value of a number.
Syntax
Math.abs(x)
Parameter values
x Required. Must be a numeric value.
Return value
The absolute value of Number x. Returns NaN if x is not a number, or 0 if x is null.
Example
In this example, I will get the absolute values of different types of arrays:
var a=Math.abs(7.25); var b=Math.abs(-7.25); var c=Math.abs(null); var d=Math.abs("Hello"); var e=Math.abs(2+3);
Output results:
7.25 7.25 0 NaN 5
Recommended learning:《javascript advanced tutorial》
The above is the detailed content of How to output absolute value in JavaScript. For more information, please follow other related articles on the PHP Chinese website!