In other words; a variable can be used before it has been declared.
Example 1 gives the same result as Example 2:
To understand this, you have to understand the term "hoisting".
Example 1 does not give the same result as Example 2:
Does it make sense that y is undefined in the last example?
This is because only the declaration (var y), not the initialization (=7) is hoisted to the top.
Because of hoisting, y has been declared before it is used, but because initializations are not hoisted, the value of y is undefined.
Example 2 is the same as writing:
If a developer doesn't understand hoisting, programs may contain bugs (errors).
To avoid bugs, always declare all variables at the beginning of every scope.
Study "use strict" in the next chapter.