function scopeDemo() { var a = 5; if (true) { var b = 10; } // This will work alert(b); } scopeDemo();