Promotion order of JS function declaration and variable declaration

now we all agree that the promotion of function declaration takes precedence over the promotion of variable declaration. Can you give me an example to prove this point?

the following example does not prove this point

console.log(person); // person() { console.log("function")}
function person() {
    console.log("function")
}
console.log(person); // person() { console.log("function")}
var person = "variable";
console.log(person);//variable

whether variable declaration or function declaration takes precedence, the result is the same;

// 
var person;
function person() {
    console.log("function")
}
console.log(person); // person() { console.log("function")}
console.log(person); // person() { console.log("function")}
person = "variable";
console.log(person);//variable

// 
function person() {
    console.log("function")
}
var person;
console.log(person); // person() { console.log("function")}
console.log(person); // person() { console.log("function")}
person = "variable";
console.log(person);//variable

Please give us an example that can be proved, or if there is anything wrong with the above, thank you very much

Mar.11,2021

That's what it says in the

standard.

the code that follows you declares variables first and then declares functions. The person you get at the beginning is a function, and vice versa, which means that the priority of function declaration should be high.
otherwise, the first one is the variable and the second is the function. Or the next priority is high.

variable declaration hints that the default value of the variable at the beginning of the function is the default value of the variable. During the execution of the function, you can certainly assign other values to the function

.

http://zonxin.github.io/post/.


The
  

function declaration takes precedence, and subsequent variable declarations are ignored, as the standard says.
an error should be reported if the variable declaration takes precedence and then the function is declared.

Menu