javascript - how to use the es6 "let" keyword properly in a forloop -


maybe i'm not understanding es6 'let' keyword.

question:

wy iterate(10) iterate 4 times? why final output 15?

function iterate(count){   for(let = 0; < count; i++){     +=     console.log('inside', i);   }   console.log('outside', i); } iterate(10); //0 //inside 2 //inside 6 //inside 14 //outside 15 

how should go using let in for loop? when should think use let.

why iterate(10) iterate 4 times?

because increment i itself, multiply 2 in each iteration:

i += 

it has nothing let. same result var.

why final output 15?

that should throw reference error because i not available outside of loop.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -