内置对象:本身已经有的,并不需要自己再实例化或者声明
Global对象
Math对象
对浏览器地址进行编码和解码
var box='//Lee李';
alert(encodeURI(box)); //只编码了中文 //Lee%E6%9D%8E
alert(encodeURIComponent(box)); //特殊字符和中文编码了,使用频率更高一些 %2F%2FLee%E6%9D%8E
解码:decodeURI decodeURIComponent
非常危险
eval('var box=100');
alert(box); //100
Global对象包含了一些属性:undefined、NaN、Object、Array、Func tion等等
alert(Array); //返回构造函数
alert(window.Array); //返回构造函数 两者等价
alert(Math.E); //2.718281828459045
alert(Math.PI); //3.141592653589793
alert(Math.min(2,3,5,9)); //2
alert(Math.max(2,3,5,9)); //9
alert(Math.ceil(25.9)); //26
alert(Math.floor(25.9)); //25
alert(Math.round(25.5)); //26 四舍五入
random()方法
Math.random()方法返回介于0到1之间的一个随机数,不包含0和1
for(var i=0;i<10;i++){
document.write(Math.random()+'<br/>');
}
1-10之间,包括1和10
for(var i=0;i<10;i++){
document.write((Math.floor(Math.random()*10+1))+'<br/>');
}
5-10之间,包括5和10
for(var i=0;i<10;i++){
document.write((Math.floor(Math.random()*6+5))+'<br/>'); //6+5-1=10 (5-10之间)
}
function select(start,end){
var total=end-start+1;
return Math.floor(Math.random()*total+start);
}
for(var i=0;i<10;i++){
document.write(select(5,10)+'<br/>');
}
alert(Math.abs(-5)); //绝对值