I know that the execution context of JavaScript is created when a function is called. But I don't understand example below. Example 1 and Example 2 are very similar.
However, these results are not the same.
I already referenced the links.You-Don't-Konw JS and Blog reference and related to stackoverflow question
Example 1
var value = "Hello";
function bar() {
var value = "Bye";
function foo() {
return value;
}
console.log(foo());
}
bar(); // Bye
Example 2
var value = "Hello";
function foo() {
return value;
}
function bar(func) {
var value = "Bye";
console.log(func());
}
bar(foo); // Hello
I expected both results example 1 and example 2 to be Bye. If the execution context of the JavaScript is created at the time of the function call, why are the two results different?