An infinite while loop will block the main thread wich is equivalent to a crash.
You could use a selfcalling function ( wich leaves the main thread doing some other stuff inbetween):
(function main(counter){
console.log(counter);
setTimeout(main,0,counter+1);
})(0);
You can put a loop that goes from 0 to 100, and one that goes from 100 to 0 into it, without blocking the browser too much:
(function main(){
for(var counter=0;counter<100;counter++){
console.log(counter);
}
console.log(100);
while(counter){
console.log(--counter);
}
setTimeout(main,0);
})();
http://jsbin.com/vusibanuki/edit?console
Further research: JS IIFEs , function expression, non-blocking trough setTimeout …