In example 1 f2 uses global a, but in example 2 it uses a from f1 function scope because f2 is a nested function. In other words the difference in variable scope. You can about it here
f2
a
f1