In some programming language , it is called a modular level variable, the reason for doing this is to make the variable accessible for the entire module or page(for web development). Of course it is possible to access the variable inside the function. Maybe there's an error inside the function
Show how you're trying to use the variable in the function.
In JS you can, like in C.
But it's a bad practice messing with the global directly under the local scope of a function, although on some instances it's ok. But as much as possible try to hesitate from doing so; you have to seperate concerns and responsibility. In a large project or framework, if you happend to directly alter or use a global variable, you might end up screwing with other programmers in your team. They might end up debugging he code for a day, just to find out a function or a method had been referencing on a global var. Sweet, isn't it. But S&%# it happens. T_T
Anyway, you can declare a local variable by redeclaring the same variable in the function, in this way, it won't clutter the global space, or use the global variable.
Additionally, if you are having problem accessing the myvariable in your function, it would be appropriate to post in the whole definition of the function itself. As what I said earlier, you should be able to access that variable inside your function; judgin from the code you posted.