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 ...
随机推荐
- WEB前端大神之路之基础篇
CSS篇: 1.CSS权重: 不重复造轮子啦,直接传送门(CSS选择器的权重与优先规则) JavaScript篇: 1.this关键字: 它是一种引用(referent).指向的是当前上下文(cont ...
- sudo 无效命令
mac系统中由于不小心修改了/etc/sudoers下的权限为777,故而sudo命令不能使用. 解决办法 1.重新启动mac并且按command+s进入单用户界面 2.此时默认的系统状态是只读状态, ...
- GIT_linux服务器与本地环境构建
linux安装git包 很多yum源上自动安装的git版本为1.7,这里手动编译重新安装1:安装依赖包yum install curl-devel expat-devel gettext-devel ...
- common-logging源码解析
OK,现在我们来研究下common-logging的源码.这篇博客有参照上善若水的博客,感谢他的无私分享. 先来随便扯点吧,貌似所有这些流行的Logging框架都和Log4J多少有点关系(不太确定Co ...
- 无废话XML--DOM4J
Dom4j 是一个易用的.开源的库,用于 XML ,XPath 和 XSLT .它应用于 Java 平台,采用了 Java 集合框架并完全支持 DOM ,SAX 和 和 JAXP .我们可以很 ...
- 【转】高精度GPS测量中框架基准的统一
一.地面基准点的坐标基准转换 一般情况下,我们可以从IERS或IGS等机构获取最新的站坐标和速度场,这些站坐标和速度场是在某一特定基准框架和历元下的坐标值,若要提供高精度GPS网的分析使用,还需要作框 ...
- c# 事件路由器
事件转发 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...
- js实现键盘按键检测
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...
- RMI基础
远程方法调用(Remote Method Invocation,RMI)从JDK1.1就已经实现,它大大增强了Java开发分布式应用的能力.可以实现通过网络完成不同JVM间的通信,不仅可以传递基本的数 ...
- [Sdoi2017]新生舞会 [01分数规划 二分图最大权匹配]
[Sdoi2017]新生舞会 题意:沙茶01分数规划 貌似\(*10^7\)变成整数更科学 #include <iostream> #include <cstdio> #inc ...