Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript 的常见错误类型 #6

Open
SuperTapir opened this issue Apr 6, 2020 · 0 comments
Open

JavaScript 的常见错误类型 #6

SuperTapir opened this issue Apr 6, 2020 · 0 comments

Comments

@SuperTapir
Copy link
Owner

SyntaxError

在解析代码的过程中发生的语法错误。

let 1test = 20
// Uncaught SyntaxError: Invalid or unexpected token

ReferenceError

无效引用。

c = a + b
// Uncaught ReferenceError: a is not defined

RangeError

数值变量或参数超出其有效范围。

let num = 22.3333333;
num.toFixed(-1)
// Uncaught RangeError: toFixed() digits argument must be between 0 and 100

TypeError

变量或参数不属于有效类型。

null.test()
// Uncaught TypeError: Cannot read property 'test' of null

URIError

encodeURI()decodeURl() 传递的参数无效。

decodeURIComponent('%@');
// Uncaught URIError: URI malformed

EvalError

eval() 有关。

EvalError 不在当前ECMAScript规范中使用,因此不会被运行时抛出. 但是对象本身仍然与规范的早期版本向后兼容.

InternalError

代表Javascript引擎内部错误。

例:

  • "too many switch cases"(过多case子句);
  • "too many parentheses in regular expression"(正则表达式中括号过多);
  • "array initializer too large"(数组初始化器过大);
  • "too much recursion"(递归过深)。

参考资料

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant