1. SyntaxError:语法错误,例如拼写错误、缺少括号等。示范代码:
console.log('Hello, world!);
// 报错:Uncaught SyntaxError: missing ) after argument list
  1. ReferenceError:引用错误,例如引用未定义的变量或函数。示范代码:
console.log(a);
// 报错:Uncaught ReferenceError: a is not defined
  1. TypeError:类型错误,例如对不支持某个方法的数据类型使用该方法。示范代码:
var a = 123;
a.toUpperCase();
// 报错:Uncaught TypeError: a.toUpperCase is not a function
  1. RangeError:范围错误,例如超出数组的最大长度、递归调用层数过多等。示范代码:
var arr = new Array(1000000000000000000000);
// 报错:Uncaught RangeError: Invalid array length
  1. URIError:URI错误,例如使用 encodeURI()、decodeURI()、encodeURIComponent()、decodeURIComponent() 函数时传入的参数不合法。示范代码:
decodeURIComponent('%E0%A4%A');
// 报错:Uncaught URIError: URI malformed
  1. EvalError:eval 函数错误,该错误已经被废弃,不再使用。
列出js所有的错误类型 以及 如何报出此错误的 示范代码

原文地址: https://www.cveoy.top/t/topic/bRKR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录