typeof返回类型
var booleanObject = new Boolean(false);
var falseValue = 10;
alert(typeof booleanObject );//Object
alert(typeof falseValue );//number
alert(booleanObject instanceof Boolean)//truealert(falseValue instanceof Boolean)//false
var numberObject = new Nubmber(10);
var numberValue = 10;
alert(typeof numberValue);//Object
alert(typeof numberObject);//number
alert(numberObject instanceof Number)//true
alert(numberValue instanceof Number)//false
Boolean对象:可以对任何数据类型的值调用Boolean()函数,总会返回一个Boolean值
var message = "hello";
var mesageBoolean = Boolean(message);
数据类型 | 转换为true的值 | 转换为false的值 |
Boolean | true | false |
String | 非空串 | 空串 |
Number | 非零数值 | 0和nan |
object | null | |
Math对象:
min()和max() ceil() floor() round() random() abs() exp() log() sqrt()
var max=Math.max(3,4,5,6)
alert(max);//54
var min=Math.min(3,4,5,6)
alert(min);//3
获取一个数组中最大值
var values = [1,2,3,4,5,6,7,8];
var max = Math.max.applay(Math,values);
random()返回0-1之间的随机数
获取1-10之间的随机数
var num = Math.floor(Math.random()*10+1);
获取2-10之间的随机数
var num = Math.floor(Math.random()*9+2);
获取lowerValue--upperVlue之间的随机数function selectFrom(lowerValue,upperVlue){
var choices = upperValue - lowerValue+1;
return Math.floor(Math.random()*choices+lowervalue);
}
var num = selectFrom(2,10);
alert(num);//介于2-10之间
Number对象:valueof() toString() toLocalString() toFixed()
var numberObject = new Number(10);
alert(num.toFixed(2));//10.00
String对象:
charAt() concat() substring() substr() slice() split() indexOf() trim()
Array对象: