I have this code. I have written the value of 'i' (in comments) that I expected as the correct output. But the outputs/alerts are different.
Fiddle: http://jsfiddle.net/e2jbno4a/
Code:
var i = 10;
function outer() {
    alert(i); // 10
    var i = 5;
    alert(i); // 5
    function inner() {
        var i = 20;
    }
    inner();
    alert(i); // 5
    if (1) {
        var i = 30;
    }
    alert(i); // 5
    setTimout(function () {
        alert(i); // 5
    }, 100);
}
outer();
Can someone let me know the reason for the output? Or just the pointers where the specific concepts are explained?
 
    