JavaScript
/Intermediate
Hoisting
Definition
Hoisting is JavaScript's default behavior of moving declarations to the top of the current scope (script or function) prior to execution of the code.
Explain Like I'm New
Imagine you are giving a speech. Before you even start talking, the organizer reads through your speech and pulls all the character names (variable declarations) and main points (function declarations) to the top of the page. So, even if you mention a character before officially introducing them, the audience already knows they exist.
Real World Example
This is why you can call a function in your code before you actually write the function definition lines further down in the file.
Common Use Cases
- •Organizing code by placing helper functions at the bottom of a file, keeping the main logic at the top.
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- What is hoisting in JavaScript?
- Does JavaScript hoist variable initializations (assignments)?
intermediate
- How does hoisting differ between var, let, and const?
- What is the difference between function declarations and function expressions in terms of hoisting?
advanced
- What takes precedence in hoisting: variable declarations or function declarations?
- What is the Temporal Dead Zone (TDZ)?
trick
- What happens if you declare a variable with var after you've already assigned it a value?