Correction
var test = 'global value'; (function() { var test2 = 'local value'; console.log(test); })();
The real solution is to fix your code so that you don't like your shadow global variables.
Eval works
You can always use global eval, this is the most reliable.
Example
var test = 'global value'; function runEval(str) { return eval(str); } (function() { var test = 'local value'; console.log(runEval("test")); })();
If you don't like defining a global rating, you can use Function to do this indirectly.
Living example
var test = 'global value'; (function() { var test = 'local value'; console.log(new Function ("return test;") () ); })();
Other hacks
The following operations are performed in non-standard mode.
(function () { var test = "shadowed"; console.log(this !== undefined && this.test); })();
And this hack works in broken implementations
(function() { var test = 'local value'; try { delete test; } catch (e) { } console.log(test); })();
source share