数学对象
1.保存的是一些数学信息和公式;
2.对象:Math (是一个静态对象);
3.向上求整:Math.ceil();
Eg: Math.ceil(1.3); 2
Math.ceil(-1.3); -1
4.向下求整:Math.floor()
Eg: Math.floor(-1,3) -2
Math.floor(true) 1
5.四舍五入求整:Math.round()
6.最大值:Math.max()
Eg: Math.max(1,0,-1,true,”a”) NaN(因为”a会转成NaN”)
对数组求最大值:
var arr=[1,2,3,56];
(此时需要用到apply改变this指向)
Var max = Math.max.apply(window,arr)
7.最小值: Math,min()
8.随机数: Math,random()
取值范围(0,1)
返回值是0-1之间的浮点数
Eg: 1-10之间的浮点数
公式:Math.floor(Math.random()*(max-min+1) +min)
console.log(Math.floor(Math.random()*10+1)
9.绝对值: Math.abs()
10.次方:Math.pow()
Eg: Math.pow(2,3) 8