通过typeof关键字检测数据类型
typeof可返回被检测的数据类型,支持两种语法
// let age = 18 //数字型
// let uname = '张三岁' //字符串
// let flag = false //布尔型
// let buy //未定义类型
// console.log(age)
// console.log(uname)
// console.log(flag)
// console.log(buy)
let num = 10
console.log(typeof num) //number
let str = '张三岁'
console.log(typeof str) //string
let str1 = '10'
console.log(typeof str1) //string
let flag = false
console.log(typeof flag) //boolean
let buy
console.log(typeof buy) //undfined
let obj = null
console.log(typeof obj) //null
评论