javascript内置对象

javascript内置对象

一:Global全局对象

这个对象是不存在的,不属于任何其他对象的属性和方法都属于它。

属性和方法:

1:URI编码方法:

encodeURI()对汉字编码;encodeURIComponent()对任何非标准字符进行编码。

decodeURI()对汉字解码;decodeURIComponent()对任何非标准字符进行解码。

var str='//abc苏';
console.log(encodeURI(str));            // //abc%E8%8B%8F
console.log(encodeURIComponent(str));   // %2F%2Fabc%E8%8B%8F
console.log(decodeURI(encodeURI(str))); // //abc苏
console.log(decodeURIComponent(str))    // //abc苏

2:eval()方法:

字符串解析器的作用,参数是javascript代码。

eval('var box=100');

alert(box);  //100

3:属性undefined,NaN,Object,Array,Function等等。

alert(Array):返回构造函数。

4.window对象。

通过window对象实现全局访问。

二:Math对象

1.Math 对象的属性:

 

 

Math.E

自然对数的底数,即常量e的值

Math.LN10

10的自然对数

Math.LN2

2的自然对数

Math.LOG2E

2为底e的对数

Math.LOG10E

10为底e的对数

Math.PI

∏的值

Math.SQRT1_2

1/2的平方根

Math.SQRT2

2的平方根

 

 

 

2 min()和max()方法

3 舍入方法

 

2.min()和 max()方法

Math.min()用于确定一组数值中的最小值。

Math.max()用于确定一组数值中的最大值。

alert(Math.min(2,4,3,6,3,8,0,1,3)); //最小值

alert(Math.max(4,7,8,3,1,9,6,0,3,2)); //最大值

求数组里的最小值Math.min.apply(null,arr);

3:.舍入方法

Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数;

Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数;

Math.round()执行标准舍入,即它总是将数值四舍五入为最接近的整数;

4: random()返回0到1之间的一个随机数,不包括0和1.

随机数:

function selectFrom(lower,upper){
	var sum=upper-lower+1;
	return Math.floor(Math.random()*sum+lower);
}
for(var i=0;i<10;i++){
	document.write(selectFrom(5,10));
	document.write('<br/>')
}

5 :其它方法:

 

 

Math.abs(num)

返回num的绝对值

Math.exp(num)

返回Math.Enum次幂

Math.log(num)

返回num的自然对数

Math.pow(num,power)

返回numpower次幂

Math.sqrt(num)

返回num的平方根

Math.acos(x)

返回x的反余弦值

Math.asin(x)

返回x的反正弦值

Math.atan(x)

返回x的反正切值

Math.atan2(y,x)

返回y/x的反正切值

Math.cos(x)

返回x的余弦值

Math.sin(x)

返回x的正弦值

Math.tan(x)

返回x的正切值

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值