基础数据类型:
字符串 string
数字(整型浮点型) number
布尔 boolean
null 空对象
undefined 未定义
复杂数据类型:
数组 Array
对象 Object
检测数据类型的两种基本⽅法
typeof()
Object.prototype.toString.call(‘数据’) //鉴别复杂数据类
型、引⽤数据类型
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>深度讲解JS的数据类型</title>
</head>
<body>
<script>
//字符串 string
console.log(typeof('china'))
//数字 number
console.log(typeof(123))
//布尔 boolean
console.log(typeof(true))
//null object
console.log(typeof(null))
//undefined undefined
console.log(typeof(undefined))
//对象 object object
//console.log(typeof({}))
console.log(Object.prototype.toString.call({})) // object Object
//数组 array object
//console.log(typeof([]))
console.log(Object.prototype.toString.call([])) // object Array
</script>
</body>
</html>
效果图: