Unexpected Infinite Loop



For some reason, this code turns into an infinite loop.

var understand = 1;

while(understand = 1) {
    console.log("I'm learning while loops!");
    understand = 0;


On your while statement, you used = instead of ==

= (assignment operator) is used to assign a value to a variable, element of an array, or property of an object
== (equality operator) is used to compare two values or expressions


Thank You!!! I don't know what else to say, but thanks!


Additionally, it's best to use 3 equal signs, ===, since:
== : equal to
=== : equal value and equal type


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