Js function vars Promotion Order?

  node.js, question
function a(b){
 var b;
 console.log(b);  //Why is the result 2
 bracket
 a(2);
 
 function a(b){
 var b = 4;
 console.log(b);  //Why is the result 4
 bracket
 a(2);

This is the arguments and variable priority before and after the assignment is not the same?

The parameters of the passed-in function are local variables of this function

The first function a(2) because B is already a local variable of this functionvar bIn fact, nothing has been done

Second functionvar b = 4In fact, B has been re-assigned to 4.

Summary: The variable is still the variable, the only difference is that the second function has been reassigned.

The last question, in fact, has no priority. The variable with the same name is changed againvarDefinition, will be ignored.