I am reading some question where i find this code, it seems to be easy but i can't understand how this function:(function() {} ())
works.
Please help me to understand that how the value of var foo=6
and bar=9
is only consider in bar=bar+foo
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var foo = 6;
bar = 10;
(function () {
var foo = 5;
bar = 9;
}())
bar = bar + foo;
document.getElementById("demo").innerHTML = "Final value is " + bar;
</script>
</body>
</html>