JS中的数据类型

JS中的数据类型

一、数据类型

基本数据类型(栈内存)引用数据类型(堆内存)
numberobject(普通对象、数组对象、…)
stringfunction
boolean
null
undefined
symbol(ES6)
bigint(ES6)

二、数据类型检测

方法名作用使用案例
typeof检测数据类型,返回类型名称typeof(2) --> number
instanceof检测是否为某个类型的实例,返回 ture/false[1, 2] instanceof Array --> true
constructor检测构造函数,返回 ture/false,纯数字、null、undefined不可用[1,2].constructor == Array --> true
Object.prototype.toString.call检测数据类型,返回[object,Type]Object.prototype.toString.call(1) --> “[object Number]”

三、数据类型转换

转换成Number类型:Number(“123”)、parseInt(“123”)、parseFloat(“123.44”)、isNaN(“123”)、…

表达式
true1
false0
null0
undefinedNaN
Number(“”)0
parseInt(“”)NaN
isNaN(“”) --> isNaN(0)false
parseInt(null) --> parseInt(“null”)NaN
Number(null)0
isNaN(null) --> isNaN(0)false
parseInt(“16px”)16
Number(“16px”)NaN
isNaN(“16px”) --> isNaN(NaN)true
parseFloat(“1.2px”) + parseInt(“2px”) + typeof parseInt(null) --> 1.2 + 2 + typeof NaN --> 2.2 + “number”“2.2number”
isNaN( Number( !!Number( parseInt(“0.2”) ) ) )false
typeof !parseInt(null) + isNaN(null)booleantrue
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值