Eval is inbuilt function to execute string as javascript in run time via directly access of javascript interpreter. There are multiple articles on the web to explain execution context of the eval. In essence, Eval use scope chain of calling function to execute. In this article, I am trying to explain it using very simple diagram and example. First I explain function scope chain and correlated it with how use calling function scope chain during execution.
How function scope chain work?
In above diagram there are three context 1. Global Scope chain 2. Outer Scope chain 3. Inner Scope chain. Javascript try to find out the variable from inner scope chain to Global scope chain always. Let’s go step by step to analysis output of the program
Statement console.log(a) output
Interpreter start search this variable in inner scope chain, since this present in inner scope that’s why output isinner
Statement console.log(b) output
Interpreter start search this variable in inner scope chain, since this variable is not present in inner scope try to find it in outer scope chain. since this present in outer scope that’s why output is outer.
Statement console.log© output
interpreter doesn’t find this variable in inner and outer scope chain that’s why look into global scope chain. since this present in global scope that’s why output is global
Now it’s important to understand what will be the output if the same output statement will be passed to eval function as shown in below diagram. which scope chained will be used by eval function

Wow! Surprise! still output is same whereas we are using eval to print the output. that means eval used the same scope chain which is used by the function from which eval function is called. in essence, Eval use the scope chain of the function from which it’s called. in addition to that it’s execute in window context until unless you are not using call and apply function of javascript.