内置对象

js三种对象
1- 内置对象
2- 自定义对象
3- 浏览器对象 BOm

绝对值[1 == 1][-1 == 1]

console.log(Math.abs("-1"));//1
console.log(Math.abs("-8"));//8

ceil() 向上取整

console.log(Math.ceil(2.0003));//3
console.log(Math.ceil(-2.0003));//-2

floor() 向下取整

console.log(Math.floor(2.9));//2
console.log(Math.floor(3.1));//3
console.log(Math.floor(-3.1));//-4

max() 最大的

console.log(Math.max(10,20,30,55,3));//55

min() 最小的

console.log(Math.min(10,20,30,55,3));//3

random() 随机数

console.log(parseInt(Math.random()*10));

PI π 圆周率

console.log(Math.PI);

pow() 2的4次方

console.log(Math.pow(2,4));

round() 四舍五入

console.log(Math.round(3.5415926));

自己定义一个函数 实现系统的max方法

<script>
function myMax(m){
	var max = m[0];
	for(var i=1; i<m.length; i++){
		if(max < m[i]){
			max = m[i];
			}
		}
		return max;
	}
console.log(myMax([10,20,30,40,50]));
</script>
<script>
function myMax1(){
	var max = arguments[0];
	for(var i = 0; i < arguments.length; i++){
			if(max < arguments[i]){
				max = arguments[i];
			}
		}
			return max;
	}
console.log(myMax1(10,20,3,5,31,24));
</script>

自己定义一个对象 实现系统的max方法

<script>
	function MyMath(){
		//添加一个方法 获取最大值
		this.getMax = function(){
			var max = arguments[0];
			for(var i = 0; i < arguments.length; i++){
				if(max < arguments[i]){
					max = arguments[i];
				}
			}
			return max;
		}
	}
	var mx = new MyMath();
	console.log(mx.getMax(10,20,30,35,5232,1));
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值