1. syntaxError 语法错误
- 变量名不标准:
var 1 = 1; // Uncaught SyntaxError: Unexpected number
var 1a = 1; // Uncaught SyntaxError: Invalid or unexpected number
- 关键字赋值:
new = 1; // Uncaught SyntaxError: Unexpected token =
- 根本语法错误:
var a = 5: // Uncaught SyntaxError: Unexpected token :
2. ReferenceError 援用谬误
- 变量或者函数未被申明:
fn(); // Uncaught ReferenceError: fn is not defined
- 给无奈被赋值的对象赋值时:
console.log() = 2; // Uncaught ReferenceError: Invalid left-hand side in assignment
3. RangeError 范畴谬误
- 数组长度赋值为正数:
var arr = [1, 2, 3];
arr.length = -1; // Uncaught RangeError: Invalid array length
- 对象办法参数超出可行范畴
var num = 66.66;
num.toFixed(-1); // Uncaught RangeError: toFixed() digits argument must be between 0 and 100
4. TypeError 类型谬误
- 调用不存在的办法:
123(); // Uncaught TypeError: 123 is not a function
// 会先判断是否可能是函数,像 123 就不可能是函数,所以间接报类型谬误,而如果是非法的函数名,则报 ReferenceError
var obj = {}
obj.say(); // Uncaught TypeError: obj.say is not a function
- 实例化原始值:
var a = new 1; // Uncaught TypeError: 1 is not a constructor
5. URIError URI 谬误
URI: URIFORM RESOURCE IDENTIFIER 对立资源标识符
URL: URIFORM RESOURCE LOCATOR 对立资源定位符
URN: URIFORM RESOURCE NAME 对立资源标识符
URI 包含 URL 和 URN
decodeURI("%abc"); // Uncaught URIError: URI malformed