JavaScript 中有五种可包含值的数据类型:
字符串(string)
数字(number)
布尔(boolean)
对象(object)
函数(function)
有三种对象类型:
对象(Object)
日期(Date)
数组(Array)
同时有两种不能包含值的数据类型:
null
undefined
typeof 运算符
可以使用 typeof 运算符来确定 JavaScript 变量的数据类型。
typeof "wanmait.com"
// 返回 "string"
typeof 3.14
// 返回 "number"
typeof NaN
// 返回 "number"
typeof false
// 返回 "boolean"
typeof [1,2,3,4]
// 返回 "object"
typeof {name:'Wanmait.com', birthdayYear:2008}
// 返回 "object"
typeof new Date()
// 返回 "object"
typeof function () {}
// 返回 "function"
typeof myCar
// 返回 "undefined"
* typeof null
// 返回 "object"

0条评论
点击登录参与评论