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.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site

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.

Web Design Sections
Java Script Quick Reference
Java Script Data Types
Java Script Reserved Words
Java Script Arithmetic Operators
Comparison Operators
Java Script Arrays
Java Script Character Encoding and Decoding
The if/else Structure
The switch/case Structure
The for Loop
The while Loop
The break Statement
The continue Statement
JavaScript Math Object
Round a Number
Determine Absolute Value
Determine Minimum and Maximum
Generating Random Numbers
Java Script Trigonometric Methods
Java Script Number Object
Format a Number as Currency
Java Script Strings
Compare Two Strings
Find a Character or a Substring Within a String
Include a Quote Character in a String
Include a Backslash Character in a String
Define Lines in a String
Use Escape to Replace Dangerous Characters
Convert a Number to a String
Convert a String to a Number
The Document Object Model (DOM)
Accessing Web Page Elements
Interactively Set Webpage Colors
Get Webpage File Date and File Size
Dueling Windows
Cookie Power Made Easy

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269