Global variables are actually the default in JavaScript. The keyword var is actually what causes the variable you are assigning to be placed in the local scope. If you want to declare a variable in the global scope from within any function, just omit the var keyword:
(function () {
x = 5;
})();
alert((x * 10)); // alerts "50"
This is really bad practice though, so refrain from doing so if at all possible. Littering the global scope with variables specific to your code can cause problems with other libraries (which hopefully follow this rule themselves). There's almost always a way to easily and cleanly avoid this situation. As a last resort, you can enclose the code that requires this global variable in a closure and declare it as local within that scope; in this way, the variable that used to be 'truly' global (a property of window) is now 'global' to the code within that closure. For example:
(function () {
var x = 5;
alert((x*10)); // alerts "50"
// All code here can access x as if it were 'global'.
});
alert(x * 20); // This line throws an error because x is not defined here.