JS篇(002)-js中如何检测一个变量是String 类型
文章目录
答案:三种方法
(typeof、constructor、Object.prototype.toString.call())
解析:
①typeof
typeof('123') === "string" // true
typeof '123' === "string" // true
②constructor
'123'.constructor === String // true
③Object.prototype.toString.call()
Object.prototype.toString.call('123') === '[object String]' // true

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论