is the var inside the while loop necessary in the following loop.

hi everyone! question. is the var inside the while loop necessary in the following loop. I don't think so. Just asking.
var answer = prompt("are we there yet?");
while(answer.indexOf("yes") === -1) {
var answer = prompt("are we there yet?");
}
alert("YAY, WE MADE IT!!!");
 
 
what I mean is, you could use answer=prompt("are we there yet?"); to update the value of answer, right?
You already invited:

Benny

Upvotes from:

Yes, you dont need var inside the loop, thats basically reinitializing the variable. However, var is functional scope and not block scoped. So keeping/removing var wont change anything in this case.

If you wanna answer this question please Login or Register