javascript中提供typeof来判断对象或其属性的类型,返回的类型有:number、string、object、function和undefined
js中判断时有两种写法,typeof(xxx) 或者 typeof xxx
示例:
var Person = {
name:"张三",
age:16,
say:function(){
alert("Hello World");
},
idCard:{
num:"342923198701131111",
createDate:"2010-09-34"
}
}
console.log(typeof Person.name); //string
console.log(typeof Person.age); //number
console.log(typeof Person.say); //function
console.log(typeof Person.idCard);//object
console.log(typeof Person.sex); //undefined