If you run this program and click on the "Do function f1" button, you'll see "The value of a is 2", and if you click on the "Do function f2" button, you'll see an error dialog indicated that variable a is undefined. This is as you would expect, because variable a was declared within function f1 and is therefore local to f1 only. Variable a was never declared within function f2.
But if the first statement in function f1 is changed from "var a = 2" to simply "a = 2" then variable a will, in fact, be treated as if it was declared globally, and if you click on the "Do function f2" button, you'll see "The value of a is 2".
I should mention that this was tested with Internet Explorer only. I do not know how other browsers would behave.