The first example will either add or modify the global variable x, which is generally to be avoided if not the desired outcome.
While your second example works as desired (no side effects) an alternative that looks better in my opinion would be
function bar()
{
for (var x=0; x< 100; x++) {}
}