Block Scoping Question

Block Scoping Question
0

#1

I have a simple question about this code from YDKJS Scopes and Closures:

var foo = true;

if (foo) {
    var bar = foo * 2;
    bar = something( bar );
    console.log( bar );
}

Check out this text:

“We are using a bar variable only in the context of the if-statement, so it makes a kind of sense that we would declare it inside the if-block. However, where we declare variables is not relevant when using var, because they will always belong to the enclosing scope. This snippet is essentially “fake” block-scoping, for stylistic reasons, and relying on self-enforcement not to accidentally use bar in another place in that scope.”

I understand why someone would want to declare bar in the block, but the only other alternative is to declare bar in the global scope, correct?

edit: Nevermind, this is as simple as I thought it was. I think the wording threw me off and I ended up getting confused.