- typeof
1. typeof 可以用来判断数据的类型。
2. 用法为:
let str = '张三'
let num = 123
let boo = true
let nul = null
let unde = undefined
let arr = [1,2,3]
function fun () {}
console.log(typeof str)
console.log(typeof num)
console.log(typeof boo)
console.log(typeof nul)
console.log(typeof unde)
console.log(typeof arr)
console.log(typeof fun)
- instanseof
1.instanceof是检测当前原型对象中是否含有这个属性,可以理解为是否是这个构造函数的实例对象。
let str = '张三'
let num = 123
let boo = true
let nul = null
let unde = undefined
let arr = [1,2,3]
function fun () {}
console.log(arr instanceof Object)
console.log(fun instanceof Object)
console.log(arr instanceof Array)
console.log(fun instanceof Function)