Bucaro TecHelpHTTPS Encryption not required because no account numbers orpersonal information is ever requested or accepted by this site Custom Search

Determine Absolute Value

The absolute value is simply the value without a sign, for example the absolute value of 4, or +4, is the same as the absolute value of -4: 4. If you are creating an application that requires the absolute value of a number, use the Java Script Math.abs method.

For example if you are designing a graphics application that lets the user draw a horizontal line on the screen and you want to display the length of the line in the applications status bar.

If the user draws a line from point a = 100 pixels to point b = 50 pixels, we can subtract a - b to get the line length of 50 pixels. But what if the user draws a line from point a = 50 pixels to point b = 100 pixels? Subtracting a - b = -50 pixels. A line length of -50 pixels is a little confusing to the user.

We can solve that problem by passing the subtract statement to the Math.abs method as shown below.

```var length = Math.abs(a - b);
```

The Math.abs method will always return the result as an unsigned number.

 .menubtn { margin-top:10px; margin-left:50px; width:220px; opacity:1; border-style:solid; border-color:#009000; background-color:#66ff66; transition-property: opacity; transition-duration: 1s; transition-timing-function: ease-out; } .menubtn:hover { opacity:1; background-color:#e5ff23; } Menu - More Java Script Quick Reference RSS Feed  Follow @Stephen Bucaro
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2024 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268