🎯 Today in my mock interview, I was asked: What is Hoisting in JavaScript? Hoisting is a JavaScript mechanism where variable and function declarations are moved to the top of their scope during the compilation phase. But behavior depends on how the variable is declared: 🔹 var → Hoisted and initialized with undefined 🔹 let & const → Hoisted but not initialized (Temporal Dead Zone) Example: console.log(a); // undefined var a = 10; console.log(b); // ReferenceError let b = 20; console.log(c); // ReferenceError const c = 30; 📌 Important: var can be accessed before declaration (returns undefined) let and const cannot be accessed before declaration They remain in the Temporal Dead Zone (TDZ) Mock interviews are helping me strengthen my fundamentals daily 🚀 #javascript #frontenddeveloper #interviewprep #reactjs #webdevelopment
JavaScript Hoisting Explained: Var, Let, and Const
More Relevant Posts
-
🎯 Today in my mock interview, I was asked: What is Destructuring in JavaScript? Here’s how I answered: Destructuring was introduced in ES6. It is a way of unpacking values from arrays or properties from objects into separate variables. 🔹 Array Destructuring uses square brackets [] 🔹 Object Destructuring uses curly braces {} Example: // Array Destructuring const numbers = [1, 2, 3]; const [a, b] = numbers; // Object Destructuring const user = { name: "Aditya", age: 24 }; const { name, age } = user; In object destructuring, the variable name should match the object key (unless we rename it). Mock interviews are helping me improve daily 🚀 Small improvements every day. #javascript #frontenddeveloper #reactjs #webdevelopment #interviewprep
To view or add a comment, sign in
-
🚀 JavaScript Interview Question (Event Loop + Async/Await) What will be the output of this code? 🤔 async function foo() { console.log('A'); setTimeout(() => console.log('B'), 0); await Promise.resolve(); console.log('C'); } foo(); console.log('D'); 🧠 Think carefully before answering. This question tests your understanding of: ✅ Call Stack ✅ Microtask Queue ✅ Macrotask Queue ✅ async/await behavior ✅ Event Loop 👇 Drop your answer in the comments (in order). No cheating. No running the code 😄 I’ll share the explanation in the next post. #JavaScript #FrontendDevelopment #ReactJS #WebDevelopment #AsyncAwait #EventLoop #CodingInterview #SoftwareEngineering
To view or add a comment, sign in
-
🚨 JavaScript Interview Question What will be the output? const obj1 = { name: "Suman" }; const obj2 = { name: "Suman" }; console.log(obj1 == obj2); console.log(obj1 === obj2); At first glance, many developers expect the result to be true because both objects have the same values. But JavaScript compares objects by reference, not by value. Even if two objects contain identical properties, they are stored in different memory locations. So what do you think the output will be? #JavaScript #FrontendInterview #ReactJS #FrontendDeveloper #FrontendArchitecture #ProductBasedCompany
To view or add a comment, sign in
-
𝗪𝗵𝘆 𝗱𝗼𝗲𝘀 𝘀𝗲𝘁𝗧𝗶𝗺𝗲𝗼𝘂𝘁(..., 𝟬) 𝗿𝘂𝗻 𝗟𝗔𝗦𝗧? 😳 I used to think 0ms means it runs immediately. It doesn’t. And this confusion is exactly why so many developers struggle with asynchronous JavaScript. Here’s a quick challenge 👇 𝗰𝗼𝗻𝘀𝗼𝗹𝗲.𝗹𝗼𝗴("𝗦𝘁𝗮𝗿𝘁"); 𝘀𝗲𝘁𝗧𝗶𝗺𝗲𝗼𝘂𝘁(() => 𝗰𝗼𝗻𝘀𝗼𝗹𝗲.𝗹𝗼𝗴("𝗧𝗶𝗺𝗲𝗼𝘂𝘁"), 𝟬); 𝗣𝗿𝗼𝗺𝗶𝘀𝗲.𝗿𝗲𝘀𝗼𝗹𝘃𝗲().𝘁𝗵𝗲𝗻(() => 𝗰𝗼𝗻𝘀𝗼𝗹𝗲.𝗹𝗼𝗴("𝗣𝗿𝗼𝗺𝗶𝘀𝗲")); 𝗰𝗼𝗻𝘀𝗼𝗹𝗲.𝗹𝗼𝗴("𝗘𝗻𝗱"); What’s the output? Most developers get this wrong. Understanding this properly means you finally understand: ✅ Event Loop ✅ Call Stack ✅ Microtasks vs Macrotasks ✅ Promises If you’re learning JavaScript or preparing for interviews, this will genuinely help you. 🎥 Video link is in the comments. Comment “EVENT LOOP” if you know the correct output 👇 I’ll reply to everyone. #JavaScript #AsyncJavaScript #EventLoop #FrontendDeveloper #WebDevelopment #Coding #JSInterview
To view or add a comment, sign in
-
The scariest interview question isn’t a complicated one. It’s usually the simplest. “Can you explain closures?” Because that question quickly shows whether someone memorized JavaScript… or actually understands how it works. Closures aren’t magic. They don’t store copies of variables. They access variables from their lexical scope. That small detail explains a lot: • Why state can persist between function calls • Why async callbacks behave the way they do • Why some bugs feel unpredictable Closures aren’t an advanced trick. They’re part of the foundation of JavaScript. And in my experience, strong developers aren’t defined by frameworks or tools. They’re defined by how well they understand the fundamentals. A simple test: If someone asked you to explain closures without using the word “remember” Could you do it? #FullStackDeveloper #WebDevelopment #DeveloperRoadmam #ReactJS #JavaScript #BuildInPublic #LearningInPublic #CareerGrowth
To view or add a comment, sign in
-
🔎 Difference Between undefined and not defined in JavaScript These two terms sound similar, but they mean very different things in JavaScript — and they often show up in interviews! 1️⃣ undefined A variable is undefined when it has been declared but hasn’t been assigned a value yet. let a; console.log(a); // undefined ✔️ The variable exists ✔️ Memory is allocated ❌ No value assigned yet 2️⃣ not defined A variable is not defined when it has never been declared in the current scope. console.log(b); // ReferenceError: b is not defined ❌ The variable does not exist ❌ No memory allocated ❌ JavaScript throws an error 💡 Interview Tip Even var variables are undefined during hoisting: console.log(x); // undefined var x = 10; But this will throw an error: console.log(y); // y is not defined #JavaScript #WebDevelopment #Frontend #CodingInterview #LearnToCode
To view or add a comment, sign in
-
JavaScript Interview Question What will be the output? const obj1 = { name: "Suman" }; const obj2 = { name: "Suman" }; console.log(obj1 == obj2); console.log(obj1 === obj2); At first glance, many developers expect the result to be true because both objects have the same values. But JavaScript compares objects by reference, not by value. Even if two objects contain identical properties, they are stored in different memory locations. So what do you think the output will be? #JavaScript #FrontendInterview #ReactJS #FrontendDeveloper #FrontendArchitecture #ProductBasedCompany
To view or add a comment, sign in
-
🚨 JavaScript Async Interview Question What will be the output? async function test() { console.log("1"); setTimeout(() => { console.log("2"); }, 0); await Promise.resolve(); console.log("3"); } console.log("4"); test(); console.log("5"); This question tests understanding of: • Call Stack • Async/Await behavior • Microtask queue (Promises) • Macrotask queue (setTimeout) • JavaScript Event Loop Many developers get the order wrong the first time. What do you think the output will be? #JavaScript #FrontendInterview #AsyncJavaScript #EventLoop #ReactJS #FrontendDeveloper #ProductBasedCompany
To view or add a comment, sign in
-
🚨 JavaScript Async Interview Question What will be the output? async function test() { console.log("1"); setTimeout(() => { console.log("2"); }, 0); await Promise.resolve(); console.log("3"); } console.log("4"); test(); console.log("5"); This question tests understanding of: • Call Stack • Async/Await behavior • Microtask queue (Promises) • Macrotask queue (setTimeout) • JavaScript Event Loop Many developers get the order wrong the first time. What do you think the output will be? #JavaScript #FrontendInterview #AsyncJavaScript #EventLoop #ReactJS #FrontendDeveloper #ProductBasedCompany
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development