简体   繁体   English

JavaScript古怪 - typeof [] === typeof {}评估为'true'

[英]JavaScript Weirdness - typeof [] === typeof {} evaluates to 'true'

I know the strict equals in JS evaluates two things: equality and like-typedness 我知道JS中的严格等于评估两件事:平等和类似类型

Object.is() is the closest comparison I could find to gather further insight and it offered little further in my investigation. Object.is()是我能找到的最接近的比较,可以收集进一步的见解,它在我的调查中提供的更少。

Can anyone who groks the innards of JS better explain this? 任何了解JS内部的人都可以更好地解释这一点吗? Is an array a very very strange implementation of an object? 数组是一个非常奇怪的对象实现吗? So they are empty and evaluate the same here? 所以他们是空的并在这里评价相同的?

I'm quite perplexed and just curious. 我很困惑,只是好奇。

typeof returns the primitive type of the operand. typeof返回操作数的基本类型。 For anything other than bools, numbers, strings, functions, and undefined, this is object. 除了bool,数字,字符串,函数和undefined之外的任何东西,这都是对象。

Arrays are objects with a number of additional methods -- MDN defines them as "high-level, list-like objects," and goes on to say: 数组是具有许多其他方法的对象 - MDN将它们定义为“高级,类似列表的对象”,然后继续说:

Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. 数组是类似列表的对象,其原型具有执行遍历和变异操作的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM