简体   繁体   English

(typeof variable ==='boolean')和(typeof variable =='boolean')之间有什么区别?

[英]What's the difference between (typeof variable === 'boolean') and (typeof variable == 'boolean')?

I all, I can't figure out - in type comparison/test - why we usually use : 我所有人,我不知道-在类型比较/测试中-为什么我们通常使用:

typeof variable === 'boolean'

...and never see this one : ...再也看不到这个了:

typeof variable == 'boolean'

As it seems to me that typeof always returns a string value (the type name), I don't understand why we should test the type... of the type string ? 在我看来typeof总是返回一个字符串值(类型名称),我不明白为什么我们应该测试类型...的字符串类型?

I guess it's just common practice, and it's idiomatic because triple equals compares the types as well; 我猜这只是一种普遍的做法,而且是惯用的,因为三重等于也会比较类型; which makes more sense since you're interested in the type. 因为您对类型感兴趣,所以这更有意义。 But in practice you aren't going to see a difference in behaviour in this case. 但实际上,在这种情况下,您不会看到行为上的差异。 Also see this . 另请参阅

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

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