简体   繁体   English

JavaScript中的“ typeof str”和“ typeof(str)”有什么区别?

[英]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 footypeof (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.

相关问题 (typeof variable ==='boolean')和(typeof variable =='boolean')之间有什么区别? - What's the difference between (typeof variable === 'boolean') and (typeof variable == 'boolean')? typeof === 和 typeof == 的区别 - Difference between typeof === and typeof == JavaScript中的str.fun()/ str.fun / fun(str)有什么区别? - What's the difference between str.fun() / str.fun / fun(str) in JavaScript? (typeof variable ===“function”)和jQuery.isFunction()之间有什么区别? - What's the difference between (typeof variable === “function”) and jQuery.isFunction()? 在JavaScript中,typeof x =='y'和typeof x ==='y'之间有什么区别吗? - In JavaScript, is there any difference between typeof x == 'y' and typeof x === 'y'? typeof(/ \\ s /)和$ .type(/ \\ s /)之间的区别 - Difference between typeof(/\s/) and $.type(/\s/) Coffescript / Javascript类型的差异 - difference in Coffescript / Javascript typeof typeof foo和typeof(foo)/ delete bar和delete(bar)有什么区别,为什么我们都需要? - What's the difference between typeof foo and typeof(foo) / delete bar and delete(bar), and why do we need both? 在Javascript中使用===而不是==和typeof的原因是什么? - What's the reason to use === instead of == with typeof in Javascript? JavaScript中“ typeof $”的含义是什么? - What is meaning of “typeof $” in javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM