typeof的使用

文章介绍了JavaScript中的5种基本数据类型:number、string、null、undefined和Boolean,以及引用数据类型object。通过示例展示了typeof操作符的用法,用于确定变量的数据类型,例如null被误识别为object,未声明的变量会返回undefined,且typeof能区分字符串与数字类型。

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

JS数据类型:

5种基本数据类型,number,string,null,undefined,Boolean

一种引用数据类型object

// JS:5种基本数据类型,number,string,null,undefined,Boolean
            //一种引用数据类型object(arr,function,object)
            var res1=typeof(null);
            console.log(res1);//object
            var res2=typeof(undefined);
            console.log(res2);//undefined
            例题:
            var a=100;
            var b=a+20;
            var c=typeof(b);
            //问c的数据类型是什么?
            var res3=typeof(c);
            console.log(res3);//string
            
            //typeof可以检测未声明的变量
            let res4=typeof(f);
            console.log(res4);//undefined  未报错
            
            //typeof用来检测字符串与数字
            console.log(typeof(99));//number
            console.log(typeof('99'));//string

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值