Will only declarations of variables be overwritten

  node.js, question
var a = 10;
 
 function test () {
 a = 100;
 console.log(a);  //100
 console.log(this.a);  //10
 var a;
 console.log(a);  //Why is this output 10 in the end? Reasonable words should be undefined. Even if it is covered, isn't it covered by 100?
 bracket
 test();

var a = 10;

function test () {
 a = 100;
 console.log(a);  //100
 console.log(this.a);  //10
 var a;
 console.log(a);  //Why is this output 10 in the end? Reasonable words should be undefined. Even if it is covered, isn't it covered by 100?
 bracket
 test();
 VM9973:6 100
 VM9973:7 10
 VM9973:9 100

Don’t you run the function before asking questions? The last one clearly printed out 100, which is easy to be misunderstood, has not been studied by myself?