I’m a little embarrassed to say that I only looked this up for the first time today. Although, I’ve been programming in JavaScript for so long that I must have known this years ago, but “forgotten” as I haven’t done much JavaScript programming in the last few years. Hey, at least I retained that niggling feeling like I had to look that up!
Important: JavaScript does not have block scope.
Basically:
var x = 1; { var x = 2; } print( x ); // outputs 2