<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS 错误信息类型</title>
</head>
<body>
<fieldset>
<legend>一.语法错误: SyntaxError</legend>
<div>
1.变更名不规范:
<div>var 1 = 1; //uncaught SyntaxError: Unexpected number</div>
<div>var 1ab = 1; //Uncaught SyntaxError: Invalid or unexpected token</div>
<br>
2.系统关键字赋值
<div>new = 1; //Uncaught SyntaxError: Unexpected token '='</div>
<div>function = 1; //Uncaught SyntaxError: Unexpected token '='</div>
<br>
3.基本的语法错误
<div>var a = 1: //Uncaught SyntaxError: Unexpected token ':'</div>
<div>va r = 1; //Uncaught SyntaxError: Unexpected identifier</div>
</div>
</fieldset>
<fieldset>
<legend>二.引用错误:ReferenceError</legend>
1.变更或是函数未被声明
<div>test(); //Uncaught ReferenceError: test is not defined</div>
<div>console.log(a); //Uncaught ReferenceError: a is not defined</div>
<br>
2.给无法赋值的对象赋值
<div>var a = 1 = 2; //Uncaught SyntaxError: Invalid left-hand side in assignment</div>
</fieldset>
<fieldset>
<legend>三.范围错误:RangeError</legend>
1.数组长度赋值为负数
<div>var a = [1,2,3];</div>
<div>a.length = -1; //Uncaught RangeError: Invalid array length</div>
<br>
2.对象方法参数超出可行范围
<div>var a = 12.34</div>
<div>a.toFixed(-1); //Uncaught RangeError: toFixed() digits argument must be between 0 and 100</div>
</fieldset>
<fieldset>
<legend>四.类型错误:TypeError</legend>
1.调用不存在的方法
<div>123(); //Uncaught TypeError: 123 is not a function</div>
<div>var a = {};</div>
<div>a.say(); //Uncaught TypeError: a.say is not a function</div>
<br>
2.实例化原始值
<div>var a = new "string"(); //Uncaught TypeError: "string" is not a constructor</div>
</fieldset>
<fieldset>
<legend>五.URI错误:URIError </legend>
<div>URI: Uniform Resource Identifier</div>
<div>统一资源标识符</div>
<br>
<div>URL: Uniform Resource Locator</div>
<div>统一资源定位符</div>
<br>
<div>URN: Uniform Resource Name</div>
<div>统一资源名称</div>
<br>
<div>功能都是用来定位资源的</div>
<div>但功能上面,URI 包含有 URL 和 URN</div>
<div>URI 在于I(Identifier),可以通过ID唯一标识一个资源,类型于身份证号码</div>
<div>URL 在于L(Locator),可以通过资源的路径唯一标识一个资源,类似于详细地址</div>
<div>举个例子:</div>
<div>URN: 张三</div>
<div>URI: 身份证号码:1234567890</div>
<div>URL: 详细地址:住址协议://地球/中国/浙江省/杭州市/西湖区/雷峰塔/1314楼/520号房间/张三.人</div>
<div>通过身份证或是详细地址都可以定位到这个人</div>
<br>
<div>var a = decodeURI("%34sdgqyd%"); //Uncaught URIError: URI malformed</div>
</fieldset>
<fieldset>
<legend>六. EvalError</legend>
</fieldset>
</body>
</html>