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: