差异类型错误和引用错误 [英] Difference TypeError and ReferenceError
问题描述
TypeError:...是未定义的
和
ReferenceError:...未定义
?
ReferenceError
。 TypeError
在变量存在时发生,但是您尝试执行的操作不适合其包含的值的类型。在详细消息显示未定义的情况下,如果您有一个变量,其值是特殊的 undefined
值,则会发生这种情况,并且您尝试访问属性。
请参阅 http://javascriptweblog.wordpress.com/2010/08/16/understanding-undefined-and-preventing-referenceerrors/ 与此相关的一些讨论。
What's the differnce between
TypeError: ... is undefined
and
ReferenceError: ... is not defined
?
A ReferenceError
occurs when you try to use a variable that doesn't exist at all.
A TypeError
occurs when the variable exists, but the operation you're trying to perform is not appropriate for the type of value it contains. In the case where the detailed message says "is not defined", this can occur if you have a variable whose value is the special undefined
value, and you try to access a property of it.
See http://javascriptweblog.wordpress.com/2010/08/16/understanding-undefined-and-preventing-referenceerrors/ for some discussion related to this.
这篇关于差异类型错误和引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!