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的区别
JS中的typeof和instanceof常用来判断一个变量是否为空,或者是什么类型. typeof typeof运算符返回一个用来表示表达式的数据类型的字符串. typeof一般返回以下几个字符串: ...
- 聊聊js中的typeof
内容: 1.typeof 2.值类型和引用类型 3.强制类型转换 typeof 官方文档:typeof 1.作用: 操作符返回一个字符串,指示未经计算的操作数的类型. 2.语法: typeof ope ...
- Ext JS中的typeOf
Ext JS中的typeOf:以字符串格式,返回给定变量的类型 其中对字符串对象.元素节点.文本节点.空白文本节点判断并不准确 测试代码如下: <!DOCTYPE HTML PUBLIC &qu ...
- JS isArray、typeof、instanceof
Array.isArray() 用来检验是不是数组 var a = [1,2,3] console.log(typeof a); // object console.log(Array.isArray ...
- JavaScript中的typeof 和instanceof
Js中的instanceof 和typeof的区别 演示1 var v5=new Number("22"); document.write(typeof v5+"< ...
- js中的typeof name
js中的name 使用typeof name得到 string.. 因为name是全局变量,可以在任意浏览器中使用 . cosole.dir(window)查看.. console.log(type ...
- 关于JavaScript中的typeof与instanceof
JavaScript中typeof和instanceof可以用来判断一个数据的类型,什么时候选择使用typeof?什么时候选择使用instanceof? typeof运算符 typeof运算符返回值有 ...
- 一文搞懂js中的typeof用法
基础 typeof 运算符是 javascript 的基础知识点,尽管它存在一定的局限性(见下文),但在前端js的实际编码过程中,仍然是使用比较多的类型判断方式. 因此,掌握该运算符的特点,对于写出好 ...
- 关于javascript中的typeof和instanceof介绍
typeof用来检测给定变量的数据类型 instanceof用来检测对象的类型 typeof用来检测给定变量的数据类型(也可叫做基本类型,基本数据类型.包含undefined.boolean.stri ...
随机推荐
- python 与redis
一.redis安装 源码安装: 1.wget http://download.redis.io/redis-stable.tar.gz 2.yum install gcc 3.tar zx ...
- jinja2.exceptions.TemplateNotFound: home/index.html
问题: 检查路由路径和模版渲染方式,其他文件路径都正确,可以返回字符串,就是无法返回定义的模版,为什么flask无法启找到这个模版? 那,问题原因在哪? 在flask中,目录有着严格的定义,模版目录必 ...
- eclipse启动报错the catalog could not be loaded please ensure that you have network access and if needed have configured your network proxy
搜索关键词不对在网上查了一圈没找到合适的解决办法 去看报错的日志文件 然并卵.不过下面有个config.ini,想着以前能用现在不能用,肯定是配置问题,打开该文件 转载请注明出处http://www. ...
- 配置SESSION超时与请求超时
<!--项目的web.xml中 配置SESSION超时,单位是min.用户在线时间.如果不设置,tomcat下的web.xml的session-timeout为默认.--><sess ...
- RecyclerView用法
主界面布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...
- 《CSS动画实用技巧》课程笔记
概述 这是我学习[CSS动画实用技巧][1]的课程笔记 常用动画属性--transition [常用动画属性--transition][2] .change img{ display:block; w ...
- 04_Javascript初步第二天(下)
错误对象 try{ aa();//这是一个未被定义的方法 }catch(e){ alert(e.name+":"+e.message);//输出:ReferenceError:aa ...
- PDO prepare预处理语句
预处理语句 $dsn="mysql:host=localhost;dbname=emp"; try{ $pdo=new PDO($dsn,'root','root'); }catc ...
- SQL FOR XML PATH 和 Stuff 用法
sql stuff 用法 1.作用 删除指定长度的字符,并在指定的起点处插入另一组字符. 2.语法 STUFF ( character_expression , start , length ,cha ...
- 邮件报警(postfix)
postfix是Wietse Venema在IBM的GPL协议之下开发的MTA(邮件传输代理)软件.postfix是Wietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试.在 ...