codeSTACKr

In JavaScript, what would be the result in the console of running this code?

for (let i = 0; i < 5; i++) {
console.log(i);
}

For more JavaScript tips & tricks 👉 https://youtu.be/ZI3q-_vjSZE

4 years ago | [YT] | 197



@codeSTACKr 

For more JavaScript tips & tricks 👉 https://youtu.be/ZI3q-_vjSZE

4 years ago (edited) | 1

@sebastiancontreras9974

i = 0 so it shows the first value assigned to the binding (which is 0), then it repeats the loop until the condition of i < 5 is false (which happens after the 5th log, with the number 4, is printed). Since the Boolean false won't execute the loop, it won't print number 5. I'm just starting on JS so I'd appreciate any feedback 😋

4 years ago | 25  

@NanobyteOnline

My brain always tries to overthink this questions ...

4 years ago (edited) | 18  

@francescos7001

Eeeeasy boi

4 years ago | 6  

@simple8810

That will be the good idea if youtubeer provide us some test per week on different topics not many questions that maybe minimum 10 technical questions ,I think this will be good for students as well as owner to get many subscriber

4 years ago (edited) | 1  

@ashish_prajapati_tr

keep this up. it helps us

4 years ago | 2  

@jayjanijj

Try replacing let with var and see UNEXPECTED RESULT 😂

4 years ago | 0  

@MagnusVictorinus

EZ

4 years ago | 1  

@hajji384

I confused loops lots . hhh why?

4 years ago | 2  

@pikolino210

Technically seen none since console.log() prints a new line each time! ;P

4 years ago | 0  

@jashanpreet880

Easy peasy but i get stuck when it comes to while loops

4 years ago | 0  

@rajasekhar5135

I=0 so started from 0 onwards and condition i<5 so 0,1,2,3,4 is the output if the condition is i <=5 means 5also will be their in ouput...

4 years ago | 0  

@chetanhaobijam

Got it. 01234

4 years ago | 1  

@MichaelDarkBlue

At 4am the less than looked like a greater than. I guess I know when it is not safe to program.

4 years ago (edited) | 0  

@Niqqo

Oh i got a right answer.. go me 🤣

4 years ago | 0