js中的typeof和instanceof和===的区别
typeof:用于判断number/string/boolean/underfined类型/function,不能判断:null和object ,不能区分object和Array
instanceof:判断具体的对象类型
===:用于判断undefined和null
//五种基本类型 var num=1; var str="abc"; var bl=true; var nu=null; var undef=undefined; //三种特殊类型 var obj=new Object(); var arr2=["1",2,true]; var fun=function () { } write("-------typeof-----------") write(num,typeof num);//1 number write(str,typeof str);//abc string write(bl,typeof bl);//true boolean write(nu,typeof nu);//null object write(undef,typeof undef)//undefined undefined write(obj,typeof obj);//[object Object] object write(arr2,typeof arr2);//1,2,true object write("-----------===-----------") write(num,typeof num==="number");//1 true write(str,typeof str==="string");//abc true write(bl,typeof bl==="boolean");//true true write(nu,typeof nu==="object");//null true write(undef,typeof undef==="undefined")//undefined true write(obj,typeof obj==="object");//[object Object] true write(arr2,typeof arr2==="object");//1,2,true true write(fun,typeof fun==="function");//function () { } true write("---------instanceof---------------") write(obj,obj instanceof Object)//[object Object] true write(arr2,arr2 instanceof Array);//1,2,true true write(arr2,arr2 instanceof Object);//1,2,true true write(fun, fun instanceof Function)//function () { } true write(fun, fun instanceof Object)//function () { } true
登录后复制
以上就是js中的typeof和instanceof和===的全部内容。
相关参考:【创想鸟】
以上就是js中的typeof和instanceof和===的区别的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2728386.html