Home > front end >  Why this code foo output is the result of the 11?
Why this code foo output is the result of the 11?

Time:09-26


According to the precompiled output should not be the function foo () {}?
Don't quite understand

CodePudding user response:

Precompiled as foo statement as a function, but after the code executes twice assignment again 10 and 11

CodePudding user response:

reference 1/f, the sky wave response:
is the foo pre-compiled statement for function, but the code is executed after twice assignment again 10 and 11

Still don't quite understand, precompiled not look for the variable declarations, again looking for a function declaration? Change is not the foo should be 11 and function and 10?

CodePudding user response:

Precompiled when the function is to declare and assignment,
But when precompiled for variable is declared, not the assignment, on variable
To the variable assignment is carries on in the code execution,

CodePudding user response:

You this precompiled code and execution time goes like this:
 function bar () {
//the precompiled
Var foo.
The function foo () {

}
//execution
Foo=10;
Foo=11;
Return foo.
}

CodePudding user response:

reference 3 floor sky waves reply:
precompiled is to declare the function and assignment,
But when precompiled for variable is declared, not the assignment, on variable
To the variable assignment is carries on in the code execution,

OK, finally understand, thank you!

CodePudding user response:

The final assignment is 11 foo=XXX XXX different types is different, can be []/json/func/string/num... Eventually you assignment is 11 become digital
  • Related