Javascript learning notes (8) built-in js objects

Source: Internet
Author: User
Tags natural logarithm

1. URI Method

EncodeURI () and encodeURIComponent () encode the URI
EncodeURI () does not encode special characters belonging to the URI, such as colons, forward slashes, hello, and well characters.
EncodeURIComponent () Will encode any non-standard characters

2. eval () method: interpreted the code string in the Parameter
Copy codeThe Code is as follows:
Var msg = "hello world ";
Eval ("alert (msg)"); // "hello world"


3. Math object
The value of E in Math. e mathematics
Math. PI π Value
The square root of Math. SQRT2 2
Math. abs (num) num absolute value
Num power of Math. exp (num) e
Math. log (num) num's natural logarithm
Math. pow (num, n) num n power
Math. sqrt (num) num, square root
Inverse cosine of Math. acos (x) x
Inverse sine value of Math. asin (x) x
The arc tangent value of Math. atan (x) x
The arc tangent value of Math. atan2 (y, x) y/x
Cosine of Math. cos (x) x
Sine value of Math. sin (x) x
Math. tan (x) x tangent

4. min () and max () Methods
Copy codeThe Code is as follows:
Var max = Math. max (3,45, 67,32 );
Alert (max); // 67
Var min = Math. min (2,46, 74 );
Alert (min); // 2

5. Round decimal places to the integer Method
Math. ceil () rounded up
Math. floor () rounding down
Math. round () Rounding
Copy codeThe Code is 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 return value of the random () method is between 0 and 0 ~ A random number of 1, excluding 0 and 1
Get a random number formula in a certain range:
Random Number = Math. floor (Math. random * Total number + first value) // total number = second value-first value
Copy codeThe Code is as follows:
// Random number function within the range
Function selectFrom (lowerValue, upperValue ){
Var count = upperValue-lowerValue + 1;
Return Math. floor (Math. random () * count + lowerValue );
}

Var num = selectFrom (2, 10 );
Alert (num); // between 2 and ~ Number between 10 (including 2 and 10)

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.