Yes, you have to put var
before variable name. In this way you are declaring variable in the current scope - otherwise JS will search for it in outer scopes and if not declared in any scope - will make it global. As far as I know, in strict
mode, even global variables should be declared with var
in the global space.
P.S. This is valid for all variables, not only for those that you assign a function to