Why is the first log 0 and the second, 1 and so on. ... In the console i don't get it | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Why is the first log 0 and the second, 1 and so on. ... In the console i don't get it

for(x=0;x<=8;x++){ x+=x-x++; console.log(x) }

14th May 2022, 8:26 AM
JSON🌠
2 Réponses
+ 1
Json✌ This snippet below does the same thing without the second line in your example. I would like to say nasty things about that 2nd line as I disagree with bits of code that deliberately do nothing but cause confusion, (unless it is to try and protectively obfuscate) for(x=0;x<=8;x++){ console.log(x) }
14th May 2022, 9:15 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
I agree with Rik, generally having a simple solution that works and is easy to understand is better than an unnecessarily complicated one, I personally favor having clear and understandable code for this reason. Try looking at changing the different parts of the for loop to test your understanding of how the loop works.
14th May 2022, 9:52 AM
Adrian