美文网首页
TypeError 和 ReferenceError

TypeError 和 ReferenceError

作者: 66dong66 | 来源:发表于2017-08-19 22:48 被阅读0次

有什么差异呢

TypeError: ... is undefined
ReferenceError: ... is not defined
TypeError

值存在,但是操作方法不对,或者不存在这种方法

例如:
    var a;
    onsole.log(a.b); //Uncaught TypeError: Cannot read property 'b' of undefined
例如:
    undefined.applay()//Uncaught TypeError: Cannot read property 'applay' of undefined
ReferenceError

当你尝试使用一个不存在的变量

例如:
console.log(abc) //ReferenceError: abc is not defined

关键字 和 保留字

var void = function(){}
void()
//Uncaught SyntaxError: Unexpected token void

相关文章

网友评论

      本文标题:TypeError 和 ReferenceError

      本文链接:https://www.haomeiwen.com/subject/epcorxtx.html