Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

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.

More Java Script Code:
• Java Script Events
• Extract Part of a String
• Cookie Power Made Easy
• A Brief History of JavaScript
• JavaScript Math Object
• Java Script Character Encoding and Decoding
• Java Script Strings
• Java Script Data Types
• Get Webpage File Date and File Size
• Determine Absolute Value

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro


Fire HD
[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