JavaScript判断数据类型的方法

typeof操作符

typeof 操作符作用:是用来检测变量的数据类型。对于值或变量使用 typeof 操作符会返回如下字符串。

数据类型undefined的判断示例

变量定义了但未初始化,就是undefined

var box
alert(box)
alert(typeof box) // box是undefined类型,值是undefined,类型返回的字符串是undefined

猜你喜欢

转载自www.cnblogs.com/LO-ME/p/10659960.html
今日推荐