JavaScript Learning Notes (eight) JS built-in objects _ Basics

Source: Internet
Author: User
Tags natural logarithm square root
1.URI method

encodeURI () and encodeURIComponent () encode the URI
encodeURI () does not encode special characters that are part of the URI, such as colons, forward slashes, greetings, well words, etc.
encodeURIComponent () encodes any non-standard characters

2.eval () Method: Interpreting code strings in Parameters
Copy Code code as follows:

var msg = "Hello World";
Eval ("Alert (msg)"); "Hello World"


3.Math objects
MATH.E the value of E in mathematics
Value of math.piπ
Square root of Math.sqrt2 2
Absolute value of math.abs (num) num
Num power of MATH.EXP (NUM) E
The natural logarithm of Math.log (num) num
N-Power of Math.pow (num,n) num
Square root of math.sqrt (num) num
Anti-cosine value of Math.acos (x) x
Math.asin (x) x's Inverse chord value
Math.atan (x) x's tangent value
Math.atan2 (y,x) y/x tangent value
Cosine of Math.Cos (x) x
Sine value of Math.sin (x) x
Tangent of Math.tan (x) x

4.min () and Max () methods
Copy Code code as follows:

var max = Math.max (3,45,67,32);
Alert (max); 67
var min = math.min (2,46,74);
Alert (min); 2

5. Decimal rounding to Integer method
Math.ceil () rounded up
Math.floor () Round down
Math.Round () rounded
Copy Code code as follows:

Alert (Math.ceil (25.1)); 26
Alert (Math.ceil (25.5)); 26
Alert (Math.ceil (25.9)); 26

Alert (Math.Round (25.1)); 25
Alert (Math.Round (25.5)); 26
Alert (Math.Round (25.9)); 26

Alert (Math.floor (25.1)); 25
Alert (Math.floor (25.5)); 25
Alert (Math.floor (25.9)); 25

6. The random () method returns a random number between 0~1, excluding 0 and 1
Take a random number formula in a range:
Random number = Math.floor (math.random * total + First value)//total = second value-First value
Copy Code code as follows:

//take-in-range random number function
function Selectfrom (lowervalue,uppervalue) {
var count = Uppervalue-lowervalue + 1;
Return Math.floor (Math.random () * Count +lowervalue);
}

var num = selectfrom (2,10);
Alert (num);//number between 2~10 (including 2 and ten)
Related Article

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.