why the output “I am GLOBAL foo TOO” is coming two times
Unable to understand the logic behind its output
var foo inside if(true) {} is not creating a new variable it is just overwriting the value of foo to ‘I am GLOBAL foo TOO’. if(true) {} is not a class/function so it will not create a local variable foo and replace the value of foo above it.
What is happening inside if(true) {} is not the same as what is happening in test() there a new local variable foo is being created which will be accessible only inside this function.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.