Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

JavaScript Math Object

By Exforsys | on August 9, 2007 |
JavaScript Tutorial

JavaScript Math Object

In this JavaScript tutorial, you will learn about Math Object, usage, properties and methods of math object along with syntax and examples.

Usage of Math Object:

JavaScript Math object is used to perform mathematical tasks. But unlike the String and the Date object which requires defining the object, Math object need not be defined.  Math object in JavaScript has two main attributes:

  • Properties
  • Methods

Properties of Math Object:

The JavaScript has eight mathematical values and this can be accessed by using the Math Object. The eight mathematical values are:

  • E
  • PI
  • square root of 2 denoted as SQRT2
  • square root of 1/2 denoted as SQRT1_2
  • natural log of 2 denoted as LN2
  • natural log of 10 denoted as LN10
  • base-2 log of E denoted as LOG2E
  • base-10 log of E denoted as LOG10E

The way of accessing these values in JavaScript is by using the word Math before these values namely as

  • Math.E
  • Math.LOG10E and so on

Methods of Math Object:

There are numerous methods available in JavaScript for Math Object. Some of them are mentioned below namely:

  • abs(x) – Returns absolute value of x.
  • acos(x) – Returns arc cosine of x in radians.
  • asin(x) – Returns arc sine of x in radians.
  • atan(x) – Returns arc tan of x in radians.
  • atan2(y, x) – Counterclockwise angle between x axis and point (x,y).
  • ceil(x) – Returns the smallest integer greater than or equal to x. (round up).
  • cos(x) – Returns cosine of x, where x is in radians.
  • exp(x) – Returns ex
  • floor(x) – Returns the largest integer less than or equal to x. (round down)
  • log(x) – Returns the natural logarithm (base E) of x.
  • max(a, b) – Returns the larger of a and b.
  • min(a, b) – Returns the lesser of a and b.
  • pow(x, y) – Returns xy
  • random() – Returns a pseudorandom number between 0 and 1.
  • round(x) – Rounds x up or down to the nearest integer. It rounds .5 up.
  • sin(x) – Returns the Sin of x, where x is in radians.
  • sqrt(x) – Returns the square root of x.
  • tan(x) – Returns the Tan of x, where x is in radians.

Example for Math Object methods mentioned above:


<html>
   <
body>
      <
script type="text/javascript">
         
document.write(Math.round(5.8))

      </script>
   </
body>
</
html>

The output of the above program is

6

This is because the round() method rounds the number given in argument namely here 5.8 to the nearest integer. It rounds .5 up which gives 6.

Another example for using Math Object in JavaScript.


<html>
   <
body>
      <
script type="text/javascript">
          document.write(Math.max(8,9) + "<br />")
          document.write(Math.max(-5,3) + "<br />")
          document.write(Math.max(-2,-7) + "<br />")

      </script>
   </
body>
</
html>

Output of the above program is

9
3
-2

The above example uses the max() method of the Math object which returns the largest of the two numbers given in arguments of the max method.

« « JavaScript Windows Object Properties Part II
Microsoft Dynamics » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Ads

Free Training

RSSSubscribe 416 Followers
Ads
  • Popular
  • Recent
  • JavaScript Events Handling

    May 20, 2007 - 0 Comment
  • JavaScript Form Object

    May 19, 2007 - 0 Comment
  • Working with JavaScript DOM Objects

    June 4, 2007 - 0 Comment
  • JavaScript Objects

    August 12, 2007 - 0 Comment
  • JavaScript Window Object Timeout Methods

    August 8, 2007 - 0 Comment
  • JavaScript Event Handler

    August 2, 2007 - 0 Comment
  • JavaScript Frame object

    May 20, 2007 - 0 Comment
  • JavaScript DOM Window Object

    June 21, 2007 - 0 Comment
  • JavaScript String Object

    August 12, 2007 - 0 Comment
  • JavaScript Window Object Open Method

    July 4, 2007 - 0 Comment
  • JavaScript Objects

    August 12, 2007 - 0 Comment
  • JavaScript String Object

    August 12, 2007 - 0 Comment
  • JavaScript Date Object

    August 12, 2007 - 0 Comment
  • JavaScript Windows Object Properties Part II

    August 9, 2007 - 0 Comment
  • JavaScript Windows Object Properties Part I

    August 8, 2007 - 0 Comment
  • JavaScript Window Object Timeout Methods

    August 8, 2007 - 0 Comment
  • JavaScript Document Object Methods Part II

    August 7, 2007 - 0 Comment
  • JavaScript Document Object Methods Part I

    August 5, 2007 - 0 Comment
  • JavaScript History Object Properties and Methods

    August 5, 2007 - 0 Comment
  • JavaScript Elements and Embed Objects

    August 4, 2007 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • JavaScript Objects
  • JavaScript String Object
  • JavaScript Date Object
  • JavaScript Windows Object Properties Part II
  • JavaScript Windows Object Properties Part I

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2021. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.Accept Reject Read More
Privacy & Cookies Policy
Necessary Always Enabled