1、Javascript 共有 6 种数据类型:
(基本类型 5 种)number、string、boolean、null、undefined。
(引用类型 1 种) object。
2、typeof 检测返回 6 种: undefined、boolean、string、number、object、function
注: null 是一个只有一个值的特殊类型,表示一个空对象引用,用 typeof 检测返回是 object。
3、常见举例如下:
typeof( undefined ) // undefined
typeof(null) // object
typeof(0) // number
typeof(false) // boolean
typeof("") // string
本文介绍了JavaScript中的数据类型,包括基本类型(number、string、boolean、null、undefined)和引用类型(object)。同时,讨论了typeof操作符在检测这些类型时的返回结果,特别指出null使用typeof检测会返回'object'。通过示例展示了如何使用typeof进行类型检查。
805

被折叠的 条评论
为什么被折叠?



