Let us consider this example
function scope() {
var scope = "I am outer scope"
if(true){ var scope = "I am inner…