
js中的typeof和instanceof和===的区别
typeof:用于判断number/string/boolean/underfined类型/function,不能判断:null和object ,不能区分object和Array
instanceof:判断具体的对象类型
===:用于判断undefined和null
简介PHP轻论坛是一个简单易用的PHP论坛程序,适合小型社区和个人网站使用。v3.0版本是完全重构的版本,解决了之前版本中的所有已知问题,特别是MySQL保留字冲突问题。主要特点• 简单易用:简洁的界面,易于安装和使用• 响应式设计:适配各种设备,包括手机和平板• 安全可靠:避免使用MySQL保留字,防止SQL注入• 功能完善:支持分类、主题、回复、用户管理等基本功能• 易于扩展:模块化设计,便于
21
//五种基本类型
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和===的全部内容。
相关参考:php中文网
以上就是js中的typeof和instanceof和===的区别的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号