JavaScript中 instanceof 检测 字符串

2023-07-18前端1 分钟127 次阅读
AI 摘要salmon-ai

讨论

str只是一个以string为数据类型的值,但并不属于String对象的实例

js 复制代码
let str = 'hello'
console.log(str instanceof String)   // false
console.log(typeof str)              // string

此时strobj就是String对象的一个实例了

js 复制代码
let strobj = new String('world')
console.log(strobj instanceof String)    // true
觉得有用就点个赞,不用登录也能读

评论

0 条
登录 之后才能评论
—
还没有评论,来说第一句