问题描述
我在我的书优雅JavaScript中读到,
只有 Type c> x 和 y y 是 null 但 == 操作仍返回 true 是
这意味着 undefined == null 返回 true
strong>特别注意:
有一个以修复 typeof null
I'm reading in my book, "Elegant JavaScript", that null == true evaluates as false. Using an interpreter, I have confirmed this to be TRUE. However, later in the chapter--in fact, on the same page--, it says that when null is given as the condition of an if, while, or for statement, it will be converted to a Boolean and return false.
Can anybody with a deeper insight tell me why this is? I know where to find browser source code, but I'm not sure how to target the programming that is responsible for this peculiar and unintuive behavior. Because I know very little C++, I would also appreciate any tips on finding info like this, independently.
Thank you.
An important distinction to make is that the Type of null is Null.
(ignore typeof it returns "object" for null because of bad design and backwards compatibility)
Says that the comparison with null and a Boolean should return false because the Type of Null and Boolean are not the same, and none of the other steps in 11.9.3 apply so the default action of return false happens
The only case where the Type of x and y are different and either x or y is null but the == operation still returns true are
That means undefined == null returns true
Of special note:
There is an ES6:harmony proposal to fix typeof null
这篇关于Null是类型对象,所以它是真的吗?在幕后发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!