spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / diaries / 14

[next]

Senior Consultant/Information Security - permanent position (TX)
Next Step Systems
US-TX-Irving

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

The JavaScript Diaries: Part 14 - The Math Object

  1. Introduction
  2. Data Types & Variables
  3. Operators
  4. Functions
  5. Conditional Statements and Loops
  6. Objects
  7. Browser-Based Objects
  8. Window Methods
  9. Window Event Handlers
  10. Navigator, Screen, History and Location Objects
  11. Arrays: Part 1 - Introduction
  12. Arrays: Part 2 - Multiple Array Types
  13. Arrays: Part 3 - Array Properties and Methods
  14. The Math Object
  15. The Date Object

By 

The Math object is a predefined JavaScript object used to perform mathematical operations. It's also used to obtain the values of predefined mathematical constants, i.e., Pi (π) or the square root of a number. In addition, it can also be used to generate random numbers.

It's important to remember that the Math object begins with an uppercase "M." If a lower case "m" is used, the JavaScript interpreter will not recognize it as an object.

(Note: We won't cover all of these properties and methods in detail as some of them are a little more complicated than what we are dealing with right now.)

Properties

Name Description
E The value of Euler's constant, approximately 2.718
LN2 The natural logarithm of 2, approximately 0.693
LN10 The natural logarithm of 10, approximately 2.302
LOG2E The base 2 logarithm of E, approximately 1.442
LOG10E The base 10 logarithm of E, approximately 0.434
PI (π) The ratio of the circumference of a circle to its diameter, approximately 3.14159
SQRT1_2 Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707
SQRT2 Square root of 2, approximately 1.414

Using Pi

You can use this script to calculate the circumference of a circle using Pi by entering the radius:

Let's see what we did in this script.

  1. First, we created a function called circum.
  2. Then, we declared the variable radius and gave it the value of the results of a prompt box, which obtains the size of the radius from the user.
  3. Next, we declared the variable circle and gave it the formula which will calculate the actual circumference of the circle, based on the information given to the radius variable.
  4. Finally, an alert box displays the results of the calculation.

You would then add this in the body section of the page in order to call the script above:

Let's take a look at the JavaScript math methods and see what we can do with them.

home / programming / javascript / diaries / 14

[next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle

URL: