Accessing Global Vars with Window
Why doesn't window.x print out 10 ? eval("var x = 10;"); console.log(window.x); // undefined console.log(x); // 10 http://jsfiddle.net/kzd4z/1/ You have selected onLoad in the side panel, which wraps everything in an anonymous function. If you pick "No wrap" it works. Demo: http://jsfiddle.net/kzd4z/2/ You can see this by viewing source: //<![CDATA[ window.onload=function(){ eval("var x = 10;"); console.log(window.x); // undefined console.log(x); // 10 }//]]> brbcoding Expanding on @Dennis' answer, because using "No Wrap" wraps your entire function within an anonymous function, x is now part