1. For ... in and for of and forEach

for in will iterate the attribute in the container etc []. however the length of container will not changed. but the result will changed.

 

JavaScript traps

Therefore, you can use "for of" to fix this issue.

JavaScript traps

The best practise is that apply foreach 

JavaScript traps

2. "use strict"

if the variable which is not declared with "var", JS will consider it as global vairable. absolutely, it will affect your debug result.

Normally, please add 'use strict'; in the first line of your js source code. 

 

3. Be careful of "return"

JavaScript traps

Because the statement of "return" had been added ";" at the end. it will return undefine. the right way is as below:

JavaScript traps

相关文章:

  • 2021-05-30
  • 2021-05-21
  • 2022-01-20
  • 2021-09-24
  • 2022-12-23
  • 2021-12-19
  • 2021-07-02
  • 2021-12-10
猜你喜欢
  • 2021-05-26
  • 2021-10-25
  • 2022-02-20
  • 2021-06-06
  • 2021-08-10
  • 2022-12-23
  • 2021-11-23
相关资源
相似解决方案