I didn’t get why the output giving for a, b and first c in the console statement and yet why giving error for last console of c clarify me?

var a=10;
(()=>{
    c=20;
    console.log(c);
    var c = 40;
    b = 30;
    console.log(a);
})();
console.log(b);
console.log(c);

The output is
20
10
30
reference error c is not defined