js 常见错误

博客介绍了多种JavaScript错误类型,包括类型错误、引用错误、语法错误、范围错误、URI错误等,还提到循环引用对象传递给JSON.stringfy会引发错误,以及xmlHttpRequest引起的错误需确保url正确和同源策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1    类型错误  

Uncaught TypeError: undefined is not a function

eg:  

var foo = undefined;
foo();

2  引用错误

Uncaught ReferenceError: Invalid left-hand side in assignment

 

eg: 

if(doSomething() = 'somevalue')

3 循环引用的对象 传递给  JSON.stringfy  会引起错误 

Uncaught TypeError: Converting circular structure to JSON

eg:

4 Unexpected token ;

eg :

5  语法错误

Uncaught SyntaxError: Unexpected token ILLEGAL

Unterminated String Literal, Invalid Line Terminator

字符串文本未终止, 

6  类型错误

Uncaught TypeError: Cannot read property ‘foo’ of null, Uncaught TypeError: Cannot read property ‘foo’ of undefined

eg:

 

7   类型错误

Uncaught TypeError: Cannot set property ‘foo’ of null, Uncaught TypeError: Cannot set property ‘foo’ of undefined

eg:

8   范围错误

Uncaught RangeError: Maximum call stack size exceeded

eg:  函数无限递归调用

9  URI 错误

无效的  decodeURIComponent  调用所致 

10  xmlHttpRequest引起的

XMLHttpRequest cannot load [http://some/url/](http://some/url/). No ‘Access-Control-Allow-Origin’ header is present on the requested resource

确保url是正确,保证同源策略

11  InvalidStateError  无效状态错误

 

InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

引用一个无效的对象, 确保代码运行的时机正确

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值