I'm surprised that the following code works:
while(fred !== "stop"){
var fred = prompt("Should I stop or go?")
};
I'd understand this in a do while loop:
do {
code to be executed at least once
}
while (condition);
How is JavaScript able to set up the condition before the function has declared fred to be a variable?
Other questions I've read pertain to var declarations inside the conditional.
console.log(fred)beforepromptstatement, you will notice thatnullis printed bazillion times before yourpromptis even processed. That saidfredis already hoisted since it has function scope.var xis in the middle of the function, and that (and hoisting) is central to the question (and the answers answer this question).