1. URI methods
encodeURI() and encodeURIComponent() encode URI
encodeURI() will not encode special characters that are URIs themselves, such as colon, forward slash, hello, tic-tac-toe etc.
encodeURIComponent() will encode any non-standard characters
2.eval() method: interpret the code string in the parameter
var msg = "hello world";
eval("alert(msg)"); //"hello world"
3.Math object
Math.E The value of e in mathematics
Math.PI The value of π
Math.SQRT2 The square root of 2
Math .abs(num) The absolute value of num
Math.exp(num) e raised to the num power
Math.log(num) The natural logarithm of num
Math.pow(num,n) num nth power
Math.sqrt(num) square root of num
Math.acos(x) arccosine of x
Math.asin(x) arcsine of x
Math.atan( x) Arctangent of x
Math.atan2(y,x) Arctangent of y/x
Math.cos(x) Cosine of x
Math.sin(x) Sine of x Value
Math.tan(x) Tangent value of x
4.min() and max() methods
var max = Math.max(3,45,67,32);
alert(max); //67
var min = Math.min(2,46,74);
alert(min); //2
5. Method of rounding decimals to integers
Math.ceil() round up Round
Math.floor() Round down
Math.round() Round
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 and 1, excluding 0 and 1
Pick a random number within a certain range Formula:
Random number = Math.floor(Math.random * total first value) // Total number = second value - first value
//Get a 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); / /A number between 2 and 10 (including 2 and 10)