-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Open
Description
Yes, I promise I've read the Contributions Guidelines (please feel free to remove this line).
"I already searched for this issue":
Edition: (2nd)
Book Title: Scope and Closures
Chapter: 5
Section Title: Hoisting : Yet Another Metaphor
Question:
Given the following code
greeting();
function greeting() {
console.log(`Hello there!`);
}
var greeting;
What would be the value of greeting?.
It turns out my intuition was not right. Which is greeting undefined. But When I evaluate at the Dev Tools it, runs the function.
The observable behavior is like the JS Compiler holds identifier names references like a stack for functions and variables definitions, that match the order you describe in the Hoisting: Yet Another Metaphor, last secction. Function definitions are hoisted first and have more priority than variable definitions.
Metadata
Metadata
Assignees
Labels
No labels