在js中,有四种用于检测数据类型的方式,分别是:

下面我们就来分别介绍一下上面四种方法的适用场景和局限性。
typeof 用来检测数据类型的运算符
使用typeof检测数据类型,返回值是字符串格式。能够返回的数据类型
是:"number","string","bolean","undefined","function","object"。
<script>
console.log(typeof(1)); //number
console.log(typeof('hello')); //string
console.log(typeof(true)); //boolean
console.log(typeof(undefined)); //undefined
console.log(typeof(null)); //object
console.log(typeof({})); //object
console.log(typeof(function() {})); //function
</script>