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.
这两种说法有什么区别?
if (typeof errorMessage !== undefined) {}
和
if (typeof (errorMessage) !== undefined) {}
其中一个有一对完全多余的括号。
和之间的区别与和typeof foo之间typeof (foo)的区别相同。1 + 1(1) + (1)
typeof foo
typeof (foo)
1 + 1
(1) + (1)
除了 an ,typeof操作员会给你一个字符串,所以你应该比较"undefined"not undefined。
typeof
"undefined"
undefined