


Introducing the use of Math.abs() method in JavaScript_Basic knowledge
May 16, 2016 pm 03:55 PM This method returns the absolute value of a number.
Grammar
Math.abs( x ) ;
Here are the details of the parameters:
- x : a number
Return value:
- Returns the absolute value of a number
Example:
<html> <head> <title>JavaScript Math abs() Method</title> </head> <body> <script type="text/javascript"> var value = Math.abs(-1); 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 ); var value = Math.abs("string"); document.write("<br />Fourth Test Value : " + value ); </script> </body> </html>
This will produce the following results:
First Test Value : 1 Second Test Value : 0 Third Test Value : 20 Fourth Test Value : NaN

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement an online speech recognition system using WebSocket and JavaScript

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to implement an online reservation system using WebSocket and JavaScript

How to use JavaScript and WebSocket to implement a real-time online ordering system

Simple JavaScript Tutorial: How to Get HTTP Status Code

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

How to use insertBefore in javascript

How to get HTTP status code in JavaScript the easy way
