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 ...
随机推荐
- Unix/Linux命令:SED
在Unix/Linux系统中,sed命令采用逐行处理的方式对文件进行查找.删除.替换.添加.插入等操作. 语法:sed [OPTION]... {script-only-if-no-other-scr ...
- wstring操作与普通段字符操作对照表
字符分类: 宽字符函数普通C函数描述 iswalnum() isalnum() 测试字符是否为数字或字母 iswalpha() isalpha() 测试字符是否是字母 ...
- java.lang.ClassNotFoundException: com.radiadesign.catalina.session.RedisSessionHandlerValve
org.apache.tomcat.util.digester.Digester.startElement Begin event threw exception java.lang.ClassNot ...
- 五、Html表单标签
表单,表单控件的主要作用就是收集用户体验,当用户提交表单时,用户输入的内容将作为请求参数提交到远程服务器. 1,form标签 <form>:创建表单,该元素不会生成可视化的界面,但是其他控 ...
- rpc-远程调用框架
简单框架编写 http://blog.csdn.net/u013177446/article/details/67638021 netty解决拆包粘包问题 http://www.cnblogs.com ...
- android webview加载网络连接
webview = (WebView) findViewById(R.id.webview); WebSettings webSettings = webview.getSettings(); //设 ...
- 解决ubuntu系统root用户下Chrome无法启动问题
由于ubuntu16.04系统自带的是Firefox浏览器,需要安装Chrome浏览器,但是在root用户下安装后发现,Chrome无法正常启动.安装及问题解决具体如下: 1. ubuntu上Chro ...
- JavaScript数据结构 (手打代码)
array: 数组创建: ); //创建一个长度为6的数组 ,,,,,); 数组方法: var str="I love javascript"; var single=str.sp ...
- 【转】shell学习笔记(二) ——shell变量
在shell中有3种变量:系统变量,环境变量和用户变量,其中系统变量在对参数判断和命令返回值判断时会使用,环境变量主要是在程序运行时需要设置,用户变量在编程过程中使用量最多. 1 系统变量 变量名 ...
- git 对 Microsoft Word 进行版本控制
昨天中国高校发生了一件骇人听闻的事情,听说不少高校的校园网用户连接校园网被勒索病毒给黑了,重要文件全部被加密,必须要支付赎金才能解密,具体新闻可以参见:http://www.sohu.com/a/14 ...