

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the absolute value of a number in JavaScript?
To get the absolute value of a number in JavaScript, use the Math.abs() function. It returns the absolute value. The following is the parameter supported by the abs() method −
- x − A number
Example
You can try to run the following code to learn how to get the absolute value of a number −
<html> <head> <title>JavaScript Math abs() Method</title> </head> <body> <script> var value = Math.abs(-10); document.write("First Test Value : " + value ); var value = Math.abs(null); document.write("<br />Second Test Value : " + value ); var value = Math.abs(20); document.write("<br />Third Test Value : " + value ); </script> </body> </html>
- Related Questions & Answers
- How to display Absolute value of a number in C#?
- How to get a number value of a string in Javascript?
- C# Program to get the absolute value of the time
- How to get the value of a number rounded to the nearest integer in JavaScript?
- How to get the absolute coordinates of a view in Android?
- Absolute difference of Number arrays in JavaScript
- How to get the cosine of a number in JavaScript?
- How to get the sine of a number in JavaScript?
- How to get the tangent of a number in JavaScript?
- How to get the length of a Number in JavaScript?
- How to get the value of PI in JavaScript?
- How to get the square root of a number in JavaScript?
- How to get the exponent power of a number in JavaScript?
- Get the absolute value of float, int, double and long in Java
- Get Absolute value with MongoDB aggregation framework?
Advertisements