The method of obtaining the absolute value of variable in JS _javascript skill

Source: Internet
Author: User
Tags abs

This paper illustrates the method of obtaining the absolute value of variables in JS. Share to everyone for your reference. The specific analysis is as follows:

Absolute value in JS we directly use the ABS function to seek, here to sort out some of the absolute value of the variable in JS, so that we have a deeper understanding of the use of JS absolute value

JS in the absolute value is not commonly used to, today in the writing of a method encountered, and then recorded, and we learn together.

The default object--math object in JS has an ABS function, which is designed to get the absolute value of the number, such as:

Copy Code code as follows:
Math.Abs (-1); 1
Math.Abs (-2); 2

Of course, this function can also be used to get the absolute value of a variable, such as:
Copy Code code as follows:
var aaa=-3;
var bbb=abs (AAA); 3

Example:
Copy Code code as follows:
<script language= "JavaScript" >
document.write ("0 of the absolute value is:", Math.Abs (0), "<br>");
document.write ("1 of the absolute value is:", Math.Abs (1), "<br>");
document.write ("1 of the Absolute value:", Math.Abs ( -1), "<br>");
-->
</script>

Another method:
We know that the absolute value in mathematics is either Decimal or integer, and this is certainly the case.
Copy Code code as follows:
var aaa=-3.3;
var bbb=abs (AAA); 3.3

I hope this article will help you with your JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.