分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

js中的typeof和instanceof和===

发布时间:2023-09-06 01:07责任编辑:林大明关键词:js

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

原文地址:http://www.cnblogs.com/lonecloud/p/7460099.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved