I’ve been trudging through some Javascript code and encountered this loop
for (var w = window; w.window === window.window.window; w = w.window) {
w.w = w.prompt("Enter password");
if (w.w === "swordfish") break;
w.alert("Incorrect password.");
}
w.alert("Welcome, authenticated user!");
This code doesn’t really make any sense to me. What in the world is going on here and how does it work?
windowis always equal towindow.window....window, so the loop will never end, unless the password is correct.A
for(;;)loop has the following signature:It keeps continuing until
testis false. Sincewindow === windowis always true, the loop keeps running, untilbreakis encountered. For clarification,walways refers towindow.