[英]What's the difference between “typeof str” and “typeof(str)” in JavaScript?
What is the difference between these two statements? 这两个语句有什么区别?
if (typeof errorMessage !== undefined)
{}
and 和
if (typeof (errorMessage) !== undefined)
{}
One of them has a pair of entirely superfluous parentheses. 其中一个有一对完全多余的括号。
The difference between typeof foo
and typeof (foo)
is the same as the difference between 1 + 1
and (1) + (1)
. typeof foo
和typeof (foo)
之间的区别与1 + 1
和(1) + (1)
之间的区别相同。
An an aside, the typeof
operator will give you a string, so you should be comparing to "undefined"
not undefined
. typeof
说一句, typeof
运算符将为您提供一个字符串,因此您应该将其与"undefined"
而不是undefined
进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.