Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道这!!variable会将变量转换为布尔值,并且Boolean()根据 ecma262 规范,函数也将通过调用来执行类型转换ToBoolean(value)。
!!variable
Boolean()
ToBoolean(value)
我的问题是:有什么区别?!!性能优于 Boolean() 吗?
!!
它们是相同的,因为!运算符将ToBoolean()在内部调用其操作数,然后翻转该返回值,而Boolean()将ToBoolean()在内部调用其参数。
!
ToBoolean()