6. Solo Flight. Why does my code crash the browser?


#1

Can someone tell me why the following code crashes the browser?

var soloLoop = function(){
var myCondition = true;

while(myCondition = true) {
console.log("Looped once!");
myCondition = false;
}
};

soloLoop();

I know that the following code works, but I want to know why browser crashes with the code above:

var soloLoop = function(){
var myCondition = true;

while(myCondition) {
console.log("Looped once!");
myCondition = false;
}
};

soloLoop();


#2

The = true is not an accurate use because it implies that myCondition is being assigned the value of true. Instead you want to put myCondition === true but in Javascript, you can just put (myCondition) and it will mean the same thing.


#3

Wow, so I was assigning the value true to myCondition twice, and that make the browser spaz out.. interesting.

Thanks for the insight bro.


#4

All good buddy @rorygrenade . Nice site by the way...and nice city - I loved Durban! :smile:


#5

Thanks man, need to optimize the images though, need to get a better page load time, the internet here is pretty crappy a lot of the time :slightly_smiling: Also have some new projects to feature on it. Yeah Durbs is cool, how are the waves over in singapore?


#6

Haha...waves? What waves? :stuck_out_tongue:


#7

Aren't you guys close to Indo?


#8

Yeah. People go to Indonesia to surf if they're in region. Not to Singapore. We barely have beaches. I'm from Australia - waves are much better there haha.


#9

Oh okay, yeah would love to check out the gold coast hey. Anyways, shot for the info bro.