js数据类型
一. 基本数据类型-7种
1 number 数字类型
2 string 字符串
3 boolean 布尔型
4 null 空值
5 未赋值的变量默认值是undefined,类型是undefined
6 symbol 产生独一无二的值
7 bigint
<!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>
// js数据类型
// 1 基本数据类型-7种
// 2 引用数据类型-如数组、对象...
const age = 18
console.log(typeof NaN); // NaN not a number
console.log(typeof age); // 1 number 数字类型
const str = 'hello' // '' 单引号
const str2 = "hello"
const str3 = `hello` // 模版字符串 支持换行 支持表达式
console.log(typeof str3); // 2 string 字符串
const str4 = 'china'
console.log(str + 'str4'); // hellostr4
console.log(`hello${str4}`); // 'hello' + str4
// 控制台输出我今年18岁了
console.log('我今年'+age+'岁了');
console.log(`我今年${age}岁了`); // 模版字符串拼接
const str5 = "hello 'china'"
console.log(str5);
console.log('===========');
const flag = true
const flag2 = false
console.log(typeof flag);// 3 boolean 布尔型
let school // 4 未赋值的变量默认值是undefined,类型是undefined
console.log(school, typeof school); // undefined 'undefined'
let obj = null // 5 null 空值
console.log(typeof obj); // object
let s = Symbol() // 产生独一无二的值
console.log(typeof s); // 6 symbol
const num = 12n
console.log(typeof num); // 7 bigint
</script>
</body>
</html>
二. 引用数据类型-如数组、对象...