JavaScript Internal object (1)--math object

Source: Internet
Author: User

Math is one of the internal objects in JavaScript and is used primarily to handle mathematical tasks and is a static object. Unlike other dynamic objects such as date, string, and so on, it does not have a constructor, math (), and can use properties and methods directly.

For example, use the GETDATE () method of the Date object to get a day in one months:

 var New Date (); // 1. Creating an Object instance var nowdate = Date.getdate (); // 2. Using the GETDATE () method 

The Math object uses the random () method directly to produce a 0-1 stochastic number:

 var x = Math.random (); // Direct Use

Math Object Properties

document.write (Math.PI); // Output 3.141592653589793

document.write (math.e+ "<br/>");//Output 2.718281828459045document.write (math.ln2+ "<br/>");//Output 0.6931471805599453document.write (math.ln10+ "<br/>");//Output 2.302585092994046document.write (math.log2e+ "< Br/> ");//Output 1.4426950408889634document.write (math.log10e+" <br/> ");//Output 0.4342944819032518document.write (math.sqrt1_2+ "<br/>");//Output 0.7071067811865476document.write (math.sqrt2+ "<br/>");//Output 1.4142135623730951

Math Object Method

  

JavaScript Internal object (1)--math object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.