js中的typeof和instanceof和===

來源:互聯網
上載者:User

標籤:對象   eof   strong   object   boolean   fine   ber   不能   undefined   

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和===

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.