JavaScript learning notes (4) _ javascript skills

Source: Internet
Author: User
Today, I continue to learn about objects in JS. Yesterday I learned about two important objects, Array and Date, in the local object. Today, let's take a look at the built-in Global Objects and Math objects. Local object
① Array class
② Date class
Object Type built-in object
① Global Object
② Math object
Host Object
Today, I continue to learn about objects in JS. Yesterday I learned about two important objects, Array and Date, in the local object. Today, let's take a look at the built-in Global Objects and Math objects.
Global Object
The encodeURI () method is used to process the complete URI and remove spaces and other characters.
The eval () method computes a string and executes the JavaScript code.
Math object
The min () and max () methods are used to determine the maximum and minimum values of a group of numbers. Both methods can accept any number of parameters.
The ceil () method indicates the rounded up function, which always rounds up the number to the nearest value.
The floor () method indicates the downward rounding function. The number is always rounded down to the nearest value.
The round () method indicates the standard rounding function. If the difference between the number and the next integer is no more than 0.5, It is rounded up. Otherwise, it is rounded down. This Is A Rounding Rule learned in junior high school.
The pow () method is used to raise a number to the specified power, for example, to raise 2 to the 10 power (expressed as 210 in mathematics ).
The sqrt () method is used to return the square root of a specified number.
The Math object also has a complete set of trigonometric functions.
The random () method returns a random number between 0 and 1, excluding 0 and 1. This is a common tool for sites that display random quotes or news on the home page.
Not complete... Random () method example

The Code is as follows:


// Returns a random number between two integers.
Function RandomFn (strFirst, strLast ){
Var iFirst = parseInt (strFirst );
Var iLast = parseInt (strLast );
// The number between two numbers
Var iCount = iLast-iFirst + 1;
If (iCount> 0 ){
// The randdom () function returns a random decimal number between 0 and 1.
Var ranNum = Math. floor (Math. random () * iCount + iFirst); // generally, a random number is obtained in this format: multiply by the total number, then add the start number, and finally round down
Document. getElementById ('label1'). innerHTML = ranNum;
}
Else {
Alert ("integer 2 should be greater than integer 1, please enter again ");
}
}

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.