Method _ javascript technique for getting absolute values of variables in js

Source: Internet
Author: User
This article mainly introduces how to obtain the absolute value of a variable in js, and analyzes in detail how to use the abs method in js to obtain the absolute value, which has some reference value, for more information about how to obtain the absolute value of a variable in js, see the example in this article. Share it with you for your reference. The specific analysis is as follows:

Absolute Value in js we directly use the abs function to find the value. Here we will sort out some methods for getting the absolute value of the variable in js, so that you can have a deeper understanding of the usage of the absolute value of js.

The absolute values in js are not very often used. Today I encountered this problem when I wrote a method, so I recorded it and learned it with everyone.

The default object in js-The Math object contains an abs function that is used to obtain the absolute value of a number, for example:

The Code is as follows:

Math. abs (-1); // 1
Math. abs (-2); // 2


Of course, this function can also be used to obtain the absolute value of a variable, such:

The Code is as follows:

Var aaa =-3;
Var bbb = abs (aaa); // 3


Example:

The Code is as follows:

Related Article

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.