当前位置:网站首页>Const defined variables and for of and for in in JS

Const defined variables and for of and for in in JS

2022-06-23 00:55:00 Love the years Mrx

1.const The declaration is expressed as a static variable , Attempting to modify will result in an error , And the variables must be initialized when defining .

2. This variable is not allowed to be declared repeatedly

3. His scope is also a block

4.congst The declaration of only applies to variables , If you define an object , Can't change value

5. Out-of-service const Declare iteration variables , Because the iteration variable will increase automatically . But you can state that it won't be modified for Loop variable . This is right for-in and for-of Cycles are particularly meaningful

for-of and for-in difference

1.for-of Will traverse the values of the array , and for-in Only the subscripts of the array will be traversed .

2.for-of It doesn't traverse the prototype chain , and for-in Will traverse the prototype chain .

3.for-of Suitable for traversing arrays or strings , It is not suitable for traversing objects .

原网站

版权声明
本文为[Love the years Mrx]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221424364601.html