Your g variable is within the global context, so it is accessible outside of a for loop.
The loop did its job, and incremented g 10 times.
Two {} indicate a block in JavaScript and won't cause any error.
Edit: it is not alerting anything without a for loop, because the g variable is not defined.