zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    PHP之常用设计模式
    MySQL之慢查询日志和通用查询
    mysql之找回误删数据
    PHPer未来路在何方...
    如何成为更优秀的程序员
    常见的 CSRF、XSS、sql注入、DDOS流量攻击
    API接口TOKEN设计
    成为更好的程序员的八中途径
    奉秉格言
    PHP优化与提升
  • 原文地址:https://www.cnblogs.com/lonecloud/p/7460099.html
Copyright © 2011-2022 走看看