[1] Global
[1.1] Definition: The Global object is an ultimate "backstop object", properties and methods that do not attribute to any other object, are ultimately its properties and methods
[Note] All properties and functions defined in the global scope are properties of global objects. Methods such as isNaN (), Isfinite (), parseint (), parsefloat () are actually global objects
[1.2] Encoding method
[1.2.1]encodeuri (): Encodes the entire URI, replacing all invalid characters with a special UTF-8
[Note 1]encodeuri () has 82 non-encoded characters:! # $ & ' () * +,-. / : ; = ? @ _ ~ 0-9 A-Z
[1.2.2]encodeuricomponent (): Encodes a segment of a URI (commonly used to pass parameters to a Get method), replacing all invalid characters with a special UTF-8
[Note 1]encodeuricomponent () has 71 non-encoded characters:! ‘ ( ) * - . _ ~ 0-9 A-Z
[Note 2] in general, use encodeURIComponent () more than encodeURI (), because in practice it is more common to query string parameters than to encode the underlying URI
[1.2.3]decodeuri (): Decode encodeURI ()
[1.2.4]decodeuricomponent (): Decode encodeURIComponent ()
var uri = "Http://www.wrox.com/illegal value.htm#start" ;console.log (encodeURI (URI)); // http://www.wrox.com/illegal%20value.htm#start Console.log ( encodeURIComponent (URI)); // http%3a%2f%2fwww.wrox.com%2fillegal%20value.htm%23start var uri = ' http%3a%2f%2fwww.wrox.com%2fillegal%20value.htm%23start ' ; Console.log (decodeURI (URI)); // http%3a%2f%2fwww.wrox.com%2fillegal Value.htm%23start Console.log ( decodeURIComponent (URI)); // http://www.wrox.com/illegal Value.htm#start
[1.2.5]escape: Encodes a string to convert the Unicode encoding of a character into a 16-sequence
[Note 1]escape () has 69 non-encoded characters: * +-. /@ _ 0-9 A-Z
[Note 2] ECMASCRIPT3 is opposed to the use of escape () and is recommended to replace with encodeURI and encodeURIComponent, but escape () is still widely used for encoding cookies because escape () The illegal characters in the cookie are encoded exactly and the "/" that is often present in the path is not encoded.
[1.2.6]unescape (): Decode Escape ()
[1.3]eval (): Like a full ECMAScript parser, accepts only one parameter, which is the JavaScript string to execute. When the parser discovers that the eval () method is called in the code, it parses the passed-in parameter as the actual ECMAScript statement, and then inserts the execution result into the original location
[note] in strict mode, external access does not have any variables or functions created in eval (), and assigning a value to eval also results in an error
[Tips] The ability to interpret strings is very powerful, but also very dangerous. When using it to perform user input data, malicious users may enter code that threatens site or application characters, which is called Code injection
[1.4] All properties of global (18 total)
Undefined NaN Infinity Object Array Function Boolean String number Date RegExp Error evalerror rangeerror referenceerror S Yntaxerror TypeError Urierror
[tips] prohibit assigning values to undefined, Nan, and infinity
[1.5]window object: The Web browser implements the global global object as part of the Window object. Therefore, all variables and functions declared in the global scope become properties of the Window object
var color = ' red '; function Saycolor () { console.log (window.color);} Window.saycolor (); // Red
[2] Math
[2.1] Properties
MATH.E the base of the natural logarithm, that is, the value of the constant E
Natural logarithm of Math.ln10 10
Natural logarithm of MATH.LN2 2
MATH.LOG2E logarithm of base e of 2
math.log10e logarithm of base e of 10
The value of the Math.PI pie
The square root of Math.sqrt1_2 1/2, which is the reciprocal of the square root of 2.
Square root of Math.sqrt2 2
Console.log (MATH.E); // 2.718281828459045 Console.log (MATH.LN10); // 2.302585092994046 Console.log (MATH.LN2); // 0.6931471805599453 Console.log (MATH.LOG2E); // 1.4426950408889634 Console.log (math.log10e); // 0.4342944819032518 Console.log (Math.PI); // 3.141592653589793 Console.log (math.sqrt1_2); // 0.7071067811865476 Console.log (MATH.SQRT2); // 1.4142135623730951
[2.2] Method
Math.min () returns the minimum value in a set of numbers
Math.max () returns the maximum value in a set of numbers
Math.ceil (num) rounded up to an integer
Math.floor (num) rounded down to an integer
Math.Round (num) rounded to an integer
Math.random () returns a random number greater than or equal to 0 less than 1
Math.Abs (num) returns the absolute value of num
MATH.EXP (NUM) returns the NUM power of the MATH.E
Math.log (num) returns the natural logarithm of num
Math.pow (Num,power) returns the power sub power of num
MATH.SQRT (num) returns the square root of num
Math.acos (x) returns the inverse cosine value of x
Math.asin (x) returns the inverse sine value of x
Math.atan (x) returns the inverse tangent value of x
Math.atan2 (y,x) returns the inverse tangent value of y/x
Math.Cos (x) returns the cosine of X
Math.sin (x) returns the sinusoidal value of x
Math.tan (x) returns the tangent of X
Console.log (Math.min ());//1Console.log (Math.max ());//3Console.log (Math.ceil (12.6));// -Console.log (Math.floor (12.6));// AConsole.log (Math.Round (12.6));// -Console.log (Math.random ());//0.741887615993619Console.log (Math.Abs (-10));//TenConsole.log (math.exp (0));//1Console.log (Math.log (10));//2.302585092994046Console.log (Math.pow (10,2));// -Console.log (MATH.SQRT (100));//TenConsole.log (Math.acos (1) *180/math.pi)//0console.log (Math.asin (1) *180/math.pi);//90console.log (Math.atan (1) * 180/MATH.PI)//45console.log (math.atan2 *180/math.pi)//45 console.log (Math.Cos (60*math.pi/180));// 0.5000000000000001console.log (Math.sin (30*math.pi/180));//0.49999999999999994console.log (Math.tan (45*Math.PI/ 180));//0.9999999999999999
[note] The maximum and minimum methods are often used to avoid unnecessary loops and to determine the maximum number of a set of numbers in an if statement
[TIPS1] finds the largest or smallest value in the array
var values = [1,2,3,4,5,6,7,8]; var max = Math.max.apply (math,values); // 8
[TIPS2] Randomly selects a value from within an integer range
Value = Math.floor (Math.random () * Total number of possible values + first possible value)
[TIPS3] Randomly selects a value with minimum and maximum values
function Selectfrom (lowervalue,uppervalue) { var choices = uppervalue-lowervalue + 1; return Math.floor (Math.random () *choices + lowervalue);} var num = selectfrom (2,10), alert (num);
Single built-in object of JavaScript native object (Global, Math)