我是靠谱客的博主 聪慧发带,这篇文章主要介绍js中 instanceof 检测 字符串,现在分享给大家,希望可以做个参考。

如果单纯的将一个字符串赋给变量,虽然类型为string,但并不是String对象,没有创建实例。

var str = "newStr";
console.log(type of str); // true
console.log(str instanceof String); // false

 而这种通过new一个String对象的方式是属于String,但是typeof在str原型链中找到最高级,new String()出来的属于对象,因此控制台打印结果为 object

var str = new String();
console.log(typo of str); // object
console.log(str instanceof String); // true

 

最后

以上就是聪慧发带最近收集整理的关于js中 instanceof 检测 字符串的全部内容,更多相关js中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部