2.[typeof null, null instanceof Object]的结果
2020-08-21 17:18
1961 查看
2.[typeof null, null instanceof Object]的结果
(1)typeof A 返回结果是A的类型。
主要是由6种(number、string、undefined、boolean、function、object)
typeof undefined;//undefined typeof 'abc';//string typeof 123;//number typeof true;//boolean typeof {};//object typeof [];//object typeof null;//object Object.prototype.__proto__ === null //true //原型链的源头为null,所有对象都是通过null派生出来的,null本身也被定义为对象(object), //但是null不具有任何对象的特性,不能执行null.toString()、null.constructor等对象实例的默认调用, //把null可以理解为尚未存在的对象的占位符,所以'typeof null'返回object字符串。 typeof console.log//function //特别地 null == undefined; //true null === undefined; //false
(2)instanceof 用于判断构造函数的prototype属性是否在对象的原型链上
[] instanceof Array //true {} instanceof Object //true new Date() instanceof Date //true //因为null为原型链顶端,而"Object.prototype"有值(表示Object的原型对象),null值并不是以Object为原型创建出来的,显然"null instanceof Object"返回false。 Object.prototype == null //false null instanceof Object //false
(3)[typeof null, null instanceof Object]的结果
综上(1)(2)所述
[typeof null, null instanceof Object] //["object", false]
相关文章推荐
- 在 JavaScript 中为什么 typeof null 的结果是 object?为什么呢?
- 在 JavaScript 中为什么 typeof null 的结果是 object?
- object is not an instance of declaring class&argument type mismatch
- NullReferenceException: Object reference not set to an instance of an object
- NullReferenceException: Object reference not set to an instance of an object
- Vue报错 Uncaught TypeError: Right-hand side of instanceof is not an object的解决办法
- Javascript中数据类型及其判别方法(typeof instanceof Object.prototype.toSting.call(obj)的区别)
- 关于Unity3D的错误:NullReferenceException: Object reference not set to an instance of an object 的解答
- NullReferenceException: Object reference not set to an instance of an object
- typeof升级版,可以识别出array、object、null、nan、[]、{}
- type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds int,java.lang.Object
- Unity: “NullReferenceException: Object reference not set to an instance of an object”的可能解決方法
- null instanceof object
- 错误:Property or field 'default' cannot be found on object of type 'com.netflix.appinfo.InstanceInfo'
- NullReferenceException: Object reference not set to an instance of an object
- Transform.Find();FindObjectOfType();GetComponent()之间的区别
- 在使用json.dumps时遇到报错TypeError: Object of type 'float32' is not JSON serializable
- ASP.NET MVC Html.TextBox 报 Object reference not set to an instance of an object 的解决方案
- TypeError: Cannot read property 'scrollTo' of null
- 修改数据库中的内容报错:PropertyAccessException:Null value was assinged to a property of primitive type setter of