Function declaration in the eval is not overwrite the previous one

Let’s say we have code like below. The function a is declared twice times. and we know the output in the console should be

this is a2

because the second declaration of function a overwrite the previous function a.

function a ()
{
   console.log("this is a1");
}
function a ()
{
   console.log("this is a2");
}
a();

But the things are different when using eval.

Let’s say we change the code like below.

eval("function a (){console.log ("this is a1")}");

function a ()
{
   console.log("this is a2");
}
a();

the output shows

this is a1

My question is why the function a is not overwrote in this scenrio? Please shine some light on this. Many thanks.