AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
[TOC] >[success] # typeof操作符 typeof可以用来检测数据类型,但是检测不到Array,因为数组也是Object类型 ~~~ let a = undefined let b = 1 let c = '呵呵哒' let d = false let e = {} let f = [] let g = function(){} console.log(typeof a,'a') // undefined console.log(typeof b,'b') // number console.log(typeof c,'c') // string console.log(typeof d,'d') // boolean console.log(typeof e,'e') // object console.log(typeof f,'f') // object console.log(typeof g,'g') // function ~~~ 以上这些结果都可以使用3等来判断是否为字符串的对应类型,例如: ~~~ if(typeof b === 'number') ~~~ ~~~ typeof null // object 因为特殊值null会被认为是一个空的对象引用 ~~~