Other programming languages like C, C++ or Java are much more strict. There, you don’t have much freedom but in turn your end results are almost always predictable.
var x = 5;
Well, that’s something that you should understand and take note of, to avoid bugs in your scripts. So to avoid any bugs, declare and initialize all of the variables that you plan to use inside the script in the beginning of the block.