Home > Web Front-end > JS Tutorial > JavaScript study notes (4)_javascript skills

JavaScript study notes (4)_javascript skills

WBOY
Release: 2016-05-16 18:37:34
Original
775 people have browsed it

Local object
①Array class
②Date class
Type of object Built-in object
①Global object
②Math object
Host object
I will continue to learn objects in JS today. I finished learning local yesterday Two important objects in the object are Array and Date. Today, let’s take a look at the built-in objects Global object and Math object.
Global object
encodeURI() method is used to process the complete URI, removing some spaces and other characters. The
eval() method can calculate a string and execute the JavaScript code in it.
Math object
The min() method and max() method are used to determine the maximum and minimum values ​​in a set of numbers. Both methods accept any number of parameters.
The ceil() method represents the rounding function, which always rounds the number up to the nearest value. The
floor () method represents the rounding down function, which always rounds the number down to the nearest value. The
round() method represents the standard rounding function, which rounds up if the difference between the number and the next integer does not exceed 0.5, otherwise it rounds down. This is a rounding rule learned in junior high school.
The pow() method is used to raise a number to a specified power, such as raising 2 to the 10th power (expressed as 210 in mathematics).
The sqrt() method is used to return the square root of the specified number.
The Math object also has a complete set of trigonometric function methods.
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 their home page.
Not finished yet. . . random() method example

Copy code The code is as follows:

//Returns between two integers Random number
function RandomFn(strFirst, strLast) {
var iFirst = parseInt(strFirst);
var iLast = parseInt(strLast);
//The number between the two numbers
var iCount = iLast - iFirst 1;
if (iCount > 0) {
//randdom() function returns a random decimal number between 0 and 1
var ranNum = Math. floor(Math.random() * iCount iFirst);//Generally take random numbers in this format: multiply by the total number, then add the starting number, and finally round down
document.getElementById('Label1' ).innerHTML = ranNum;
}
else {
alert("Integer 2 should be greater than integer 1, please re-enter");
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template