JavaScript 中的错误类型
1、SyntaxError 语法错误
例:
var 1=1; Uncaught SyntaxError: Unexpected number var 1ab=1; Uncaught SyntaxError: Invalid or unexpected token
2、RangeError 范围错误
例:
var a=[]; a.length=-1; Uncaught RangeError: Invalid array length var b=55.55; b.toFixed(-1) Uncaught RangeError: toFixed() digits argument must be between 0 and 100
3、TypeError 类型错误
例:
var a=1; a() Uncaught TypeError: a is not a function const a=123; a=555; Uncaught TypeError: Assignment to constant variable. var obj={}; obj.a(); Uncaught TypeError: obj.a is not a function
4、ReferenceError 引用错误
例:
func(); Uncaught ReferenceError: func is not defined console.log(d) Uncaught ReferenceError: d is not defined