I have the following code:
var myFriend = 'David';
function Hi(){
var myFriend = 'Emma';
console.log(global.myFriend); //prints undefined
}
Hi();
I am trying to access the global variable myFriend inside the function. I am unable to understand why it is printing undefined. Can someone please explain?