While Loop print out


#1


https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/0/4?curriculum_id=506324b3a7dffd00020bf661


Why does the second line with 0 print out?
I thought only that which is in the console.log will print on the screen?
Thanks in advance.


var bool = 1;

while(bool){
    console.log("Less is more!");
    bool = 0;
}


#2

its console behavior. You update a variable after the last console.log, so this variable is displayed in the console

simply swap the console.log and the updating of bool


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.