Why does function expressions does not be in stack if it is invoked before its occurence?
console.log( myFunc());
var myFunc = function(){
};
Regular function declaration works right.
Why does function expressions does not be in stack if it is invoked before its occurence?
console.log( myFunc());
var myFunc = function(){
};
Regular function declaration works right.
This confusion is due to one major difference in the way that a JavaScript engine loads data into the execution context. Function declarations are read and available in an execution context before any code is executed, whereas function expressions are not complete until the execution reaches that line of code.
console.log(myFunc());
function myFunc(){
//
}
This works because of function declaration hoisting.
Without function declaration hoisting, the top of the source tree, will be empty. Hence you get the unexpected identifier
error for your code.