Home > Web Front-end > JS Tutorial > How to find the absolute value of x in javascript

How to find the absolute value of x in javascript

青灯夜游
Release: 2021-10-13 13:55:57
Original
2775 people have browsed it

In JavaScript, you can use the abs() method of the Math object to find the absolute value of x. The function of this method is to calculate the absolute value and return the absolute value of a number. The syntax "Math.abs(x )".

How to find the absolute value of x in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

In javascript, you can use the abs() method of the Math object to find the absolute value of x.

Math.abs() can return the absolute value of a number.

Syntax: Math.abs(x)

x: Required parameter, must be a value (Number type).

Return value: absolute value of x, Number type; if x is not a number, NaN is returned, if x is null, 0 is returned.

Example:

console.log(Math.abs(7.25));
console.log(Math.abs(-7.25));
console.log(Math.abs(null));
console.log(Math.abs("Hello"));
console.log(Math.abs(2+3));
Copy after login

Output result:

How to find the absolute value of x in javascript

##[Recommended learning:

javascript advanced tutorial]

The above is the detailed content of How to find the absolute value of x in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template