0
Repeat and Learn Code! Code! Code!
https://sololearn.com/coach/1239/?ref=app var expression = readLine(); for (let i = 0;i<3;i++) { console .log(expression ); }
5 ответов
+ 2
Khomi TAKAYANAGI
let is block scope means if you try to access i outside the loop it will give error but if you use var instead of let then you can access i outside the loop.
var expression = readLine();
for (let i = 0;i<3;i++)
{
console .log(expression );
}
console.log(i);//error: i is not defined
-------------
var expression = readLine();
for (var i = 0;i<3;i++)
{
console .log(expression );
}
console.log(i); //no error and print 3
+ 4
Khomi TAKAYANAGI ,
your code should work fine, so what is your question?
+ 1
Khomi TAKAYANAGI
Working fine what is issue here?
+ 1
I don't understand enough how to use "let"
+ 1
var expression = readLine()
for (var i = 0 ; i < 3 ; i ++){console.log(expression);}
it worked.
var expression = readLine()
for (var i = 0 ; i < 3 ; i ++){console.log(i);}
//no error but it outputs
0
1
2
¿How can I decide to use "var" or "let"?