typeof 判断6种
1 //typeof 6种 2 console.log(typeof 1); //number 3 console.log(typeof ''); //string 4 console.log(typeof true); //boolean 5 console.log(typeof {}); //object 6 console.log(typeof fn); //function 7 console.log(typeof undefined); //undefined
方法:
1 function isType(value){//不支持IE6 2 var str = Object.prototype.toString.call(value); 3 return str.slice(8,str.length-1).toLowerCase(); 4 }
这个比较全
1 var data = new Date(); 2 function fn(){ 3 alert(1) 4 } 5 6 console.log(isType(1)); //number 7 console.log(isType("1")); //string 8 console.log(isType(true)); //boolean 9 console.log(isType(fn)); //function 10 console.log(isType(null)); //null 11 console.log(isType(undefined)); //undefined 12 console.log(isType({})); //object 13 console.log(isType([])); //array 14 console.log(isType(/12/)); //regexp 15 console.log(isType(data)); //date
- 原始类型:数字,字符串,布尔值
- 对象类型:
- 特殊值:null(空),undefined(未定义)
对象中:特殊的有
- 数组
- 函数:以new运算符初始化,称为构造函数
- 构造函数定义了一类对象(由构造函数初始化的对象组成的集合)。类可以看做对象类型的子类型。
- js中除数组类(Array)、函数类(Function),还有日期类(Date)、正则类(RegExp)、错误类(Error)。
- js是一种面向对象的语言。
- js中,只有null、undefined无法拥有方法的值
数字:
Math对象,以下定义了很多。
NaN:它和任何值都不相等,包括自身
// 二进制浮点数和四舍五入错误 var x = 0.3 - 0.2; var y = 0.2 - 0.1; console.log(x==y);//false
日期和时间:
文本:''或""。有索引(index),有长度(length)
转义字符
匹配模式:正则