+ 8

Why output in this code is 01234 ???

Why output is 01234. My answer was 44444 Because variable "i" is displayed. https://code.sololearn.com/WPCXr1s7oC24/?ref=app Plesae explain

27th Apr 2019, 10:33 AM
Sławek J.
6 Respuestas
+ 6
You have j and i j --> from 0 to 4 (because of j++) i = 4 line 6: (j) --> 01234 (i) --> 44444
27th Apr 2019, 10:57 AM
Denise Roßberg
Denise Roßberg - avatar
+ 5
Because the i that you give to the function dosnt gets incrememtet. Just the i outside the function. What out for the different scopes.
27th Apr 2019, 10:36 AM
Dragonxiv
Dragonxiv - avatar
29th Apr 2019, 1:05 PM
Denise Roßberg
Denise Roßberg - avatar
0
Your code can be simplified with for (var j=0,i=4; i<5; i++) (function(_i) {console.log(_i);})(j) --> answer 01234 Replace with for (var j=0,i=4; i<5; i++) (function(_i) {console.log(i);})(j) --> answer 44444 to get the answer you thought Your
28th Apr 2019, 1:54 AM
Bilbo Baggins
Bilbo Baggins - avatar
0
Hi
28th Apr 2019, 11:39 PM
Kaamil Kyeremeah
Kaamil Kyeremeah - avatar
- 1
Hello era you
28th Apr 2019, 11:39 PM
Kaamil Kyeremeah
Kaamil Kyeremeah - avatar