JS 错误类
背景
SyntaxError
// 变量名错误
var 1a;
// 缺少括号
console.log 'hello');ReferenceError
// 比如我们直接打印一个未声明的变量
console.log(unknownVariable) // ReferenceError: unknownVariable is not defined
// 另一种触发场景是,将一个值分配给无法分配的对象,比如对函数的运行结果或者this赋值。
console.log() = 1 // ReferenceError: Invalid left-hand side in assignment
this = 1 // ReferenceError: Invalid left-hand side in assignment
// 上面代码对函数console.log的运行结果和this赋值,结果都引发了ReferenceError错误RangeError
TypeError
URIError
Last updated