五种基本数据类型:
1.number类型 : 数值 一切数学中的数字 作用:用于数学计算
2.string类型 : 字符串 一切以 单引号'' 双引号"" 反引号``包起来的内容 作用:用于展示文本
3. boolean类型 : 布尔 只有两个值 : true(真) false(假) 作用:用于条件判断 true:条件成立 false:条件不成立
4.null : 空值 只有一个值 null
5.undefined : 未定义 只有一个值 undefined
typeof 检测五种基本数据类型
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 检测数字 数据类型返回number(数字型)
console.log(typeof 10)
// 检测 被 双引号("") 单引号('') 反引号(``) 包裹的内容 返回string(字符串)
console.log(typeof '10')
// 检测 其他文本 返回undefined(未被定义型 只有一个值undefined)
console.log(typeof 数值)
// 检测 true或false 返回boolean(布尔型 只有两个值true(真),false(假) )
console.log(typeof true)
// 检测null 数据类型返回object 需要注意null为一个空对象
console.log(typeof null)
</script>
</body>
</html>
需要注意的是 typeof 检测 null 返回值并非为null 而是object 因为null本身为一个空对象