Different behavior in javascripts code
First :
(function(){
c();
var c=function (){
console.log("C");
}
})();
Error : Uncaught TypeError: c is not a function
vs
(function(){
c();
function c(){
console.log("C");
}
})();
C
Second :
var a;
console.log(a);
a=10;
10
vs
(function(){
var a;
console.log(a);
a=10;
})()
undefined
Please help me to understand this behaviors. Thanks!!