typeof and instanceof

本文详细介绍了JavaScript中使用typeof和instanceof进行类型检测的方法,并通过实例展示了不同内置对象(如Object、Array等)的创建方式及类型判断结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 普通方式创建typeofinstanceofnew方式创建typeofinstanceof
Objectvar o={};objectObjectvar o=new Object();objectObject
Arrayvar a=[];objectArrayvar a=new Array();objectArray
Functionvar f = function(){};functionFunctionvar f = new Function();functionFunction
Stringvar s="hello,world";string var s=new String("hello,world");objectString
Numbervar n =5;number var n =new Number(5);objectNumber
Booleanvar b=true;boolean var b=new Boolean(true);objectBoolean
nullvar nl= null;object 
undefinedvar un=undefined;undefined 
*1."typeof operator returns a string indicating the type of the unevaluated operand." ---from MDC
*2."obj instanceof ConstructorFunction works by checking if ConstructorFunction.prototype is in the prototype chain of obj. "----from MDC
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值