差异类型错误和引用错误 [英] Difference TypeError and ReferenceError

查看:147
本文介绍了差异类型错误和引用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆