typeof进行类型检测的原理

typeof 用 二进制位来标识JavaScript中的值。

000表示对象,object

010表示浮点数,001表示整数,(都是返回number类型)

100表示字符串,

110表示布尔值,

-2^30表示undefined,

null是64个0组成的二进制。 由于null全0表示,所以会被误判为对象类型。

js中数据类型分为基本数据类型引用数据类型


基本数据类型又包括:

- number 数字

- string 字符串

- boolean 布尔

- null 空对象

- undefined 未定义

- symbol 唯一值

引用数据类型:object

4.2 ECMAScript Overview ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects. In ECMAScript, an object is a collection of zero or more properties each with attributes that determine how each property can be used—for example, when the Writable attribute for a property is set to false, any attempt by executed ECMAScript code to assign a different value to the property fails. Properties are containers that hold other objects, primitive values, or functions. A primitive value is a member of one of the following built-in types: Undefined, Null, Boolean, Number, String, and Symbol; an object is a member of the built-in type Object; and a function is a callable object. A function that is associated with an object via a property is called a method.

ECMAScript是基于对象的:基本语言和主机设施是由对象提供的,而ECMAScript程序是通信对象的集群。 在ECMAScript中,对象是0个或多个属性的集合,每个属性都具有决定如何使用每个属性的属性——例如, 当属性的可写属性被设置为false时,执行ECMAScript代码为属性分配不同值的任何尝试都将失败。 属性是容纳其他对象、基本值或函数的容器。原始值是以下内置类型之一的成员: 未定义、Null、布尔、数字、字符串和符号;对象是内置类型对象的成员; 函数是可调用对象。通过属性与对象关联的函数称为方法.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值