✅ Logical Operators in JavaScript – Complete Guide with Real Examples

In this post, we’ll understand one of the most commonly asked JavaScript interview questions: What is Hoisting? I’ve also added a video below that explains hoisting visually. π
Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.
Even if you declare your variables or functions at the bottom of the file, JavaScript will act as if they were declared at the top — but only the declarations, not initializations.
console.log(x); // undefined
var x = 10;
π Explanation: The declaration var x
is hoisted to the top, but the assignment = 10
is not. So x
exists but is undefined
at the time of the console.log
.
let
or const
console.log(y); // ReferenceError
let y = 20;
Note: Variables declared with let
and const
are also hoisted but are not initialized. They remain in a temporal dead zone until the declaration is encountered.
greet(); // "Hello!"
function greet() {
console.log("Hello!");
}
✅ Function declarations are fully hoisted. So you can call the function before it's defined.
For a complete breakdown with visuals and explanations, watch the full video above or on YouTube.
Thanks for reading! If you found this helpful, don’t forget to leave a comment and share this post with fellow developers. π
Comments
Post a Comment