🧠 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐄𝐯𝐞𝐧𝐭 𝐋𝐨𝐨𝐩 – 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐅𝐚𝐯𝐨𝐫𝐢𝐭𝐞 🚀 console.log("Start"); setTimeout(() => console.log("Timeout"), 0); Promise.resolve().then(() => console.log("Promise")); console.log("End"); ✅ Output: 𝐒𝐭𝐚𝐫𝐭 𝐄𝐧𝐝 𝐏𝐫𝐨𝐦𝐢𝐬𝐞 𝐓𝐢𝐦𝐞𝐨𝐮𝐭 💡 Why? 𝐒𝐲𝐧𝐜𝐡𝐫𝐨𝐧𝐨𝐮𝐬 𝐜𝐨𝐝𝐞 𝐫𝐮𝐧𝐬 𝐟𝐢𝐫𝐬𝐭 → 𝐒𝐭𝐚𝐫𝐭, 𝐄𝐧𝐝 𝐌𝐢𝐜𝐫𝐨𝐭𝐚𝐬𝐤𝐬 (𝐏𝐫𝐨𝐦𝐢𝐬𝐞𝐬) 𝐫𝐮𝐧 𝐧𝐞𝐱𝐭 𝐌𝐚𝐜𝐫𝐨𝐭𝐚𝐬𝐤𝐬 (𝐬𝐞𝐭𝐓𝐢𝐦𝐞𝐨𝐮𝐭) 𝐫𝐮𝐧 𝐥𝐚𝐬𝐭 👉 Even with 0ms, setTimeout waits for the event loop! 🔥 Master Event Loop = Crack JS interviews #JavaScript #FrontendDeveloper #EventLoop #CodingInterview #ReactJS #TechTips
JavaScript Event Loop Explained
More Relevant Posts
-
🚀 **JavaScript Interview Question** What will be the output of this code? ```js const obj = { a: { b: 0 } }; const v1 = obj?.a?.b || 42; const v2 = obj?.a?.b ?? 42; console.log(v1, v2); ``` 🤔 **Think before you scroll...** --- #JavaScript #Frontend #WebDevelopment #CodingInterview #ReactJS
To view or add a comment, sign in
-
🚨JavaScript Interview Question What will be the output? function greet(name) { if (name === undefined) { console.log("Hello, guest!"); } else { console.log("Hello, "+ name); } greet(); greet("Anas"); greet("Anas", "How are you?"); Looks simple... but there's a twist What will be the output? Why does the last call behave differently? Bonus: How does JavaScript handle extra arguments? #JavaScript #FrontendInterview #WebDevelopment #CodingInterview #ProductBasedCompany
To view or add a comment, sign in
-
💡 **Daily React/JavaScript Interview Tip** The event loop isn’t just theory—it explains **why your code runs in a certain order**. 👉 Weak answer: “The event loop handles async operations.” ✅ Stronger answer: “JavaScript is single-threaded, so it uses the event loop to manage async tasks. Synchronous code runs first, then callbacks from the task queue (like `setTimeout`) and microtask queue (like Promises) are processed. Microtasks always run before the next task, which is why Promise callbacks execute before `setTimeout`.” 🧠 Example: ```js console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => console.log('C')); console.log('D'); ``` 👉 Output: A D C B 📌 Tip: If you can clearly explain **call stack, task queue, and microtask queue with an example**, you’ll stand out instantly. #JavaScript #EventLoop #WebDevelopment #AsyncJavaScript #TechInterviews
To view or add a comment, sign in
-
🚀 JavaScript Interview Question You Should Know ❓ What will be the output? console.log(a); var a = 10; console.log(b); let b = 20; 💡 Output: undefined ReferenceError: Cannot access 'b' before initialization 🧠 Explanation: 👉 var a Variables declared with var are hoisted They are initialized with undefined So internally: var a; console.log(a); // undefined a = 10; 👉 let b let is also hoisted BUT… It stays in the Temporal Dead Zone (TDZ) until initialized So accessing it before initialization: console.log(b); // ❌ ReferenceError let b = 20; 🎯 Key Takeaways: ✔ var → hoisted + initialized as undefined ✔ let/const → hoisted but NOT initialized (TDZ) #JavaScript #WebDevelopment #Frontend #CodingInterview #LearnToCode
To view or add a comment, sign in
-
-
💡 JS Trick: Infinite Currying This question is often asked in interviews to test your understanding of closures + function chaining. 👉 Infinite currying means calling a function repeatedly like sum(1)(2)(3)(4)... and getting the final result. ✅ How it works: 🔹 Each call stores value using closure 🔹 Returns a function again 🔹 Final value comes when evaluated 🎯 Shortcut to Remember: 👉 Function keeps returning function until final result #JavaScript #CodingInterview #Currying #Closures #Frontend #WebDevelopment #JS
To view or add a comment, sign in
-
-
JavaScript developers 👀 What will be the output? var obj = { name: "Guest", welcomeFn: function () { return "Hello " + this.name; } }; var obj2 = { welcomeFn: obj.welcomeFn, name: "User" }; console.log(obj2.welcomeFn()); Looks simple… but many get it wrong 👀 Drop your answer 👇 Explanation coming soon #JavaScript #FrontendDeveloper #InterviewPrep #ReactJS
To view or add a comment, sign in
-
🚨 React Interview Scenario (Real World) You have a component that fetches data from an API. useEffect(() => { fetchData(); }, []); Everything works fine… But suddenly: 👉 API is called multiple times 👉 Even though dependency array is empty 👀 Why is this happening? 👉 How would you fix it? Bonus: What changes in production vs development? #ReactJS #FrontendInterview #ReactHooks #JavaScript #FrontendDeveloper #WebDevelopment
To view or add a comment, sign in
-
One of the most common JavaScript interview questions: "Why does setTimeout with 0ms delay not run immediately?" Most developers cannot answer this correctly. Here is the full explanation: JavaScript is single-threaded. It can only do one thing at a time. The Event Loop is how it manages everything else. The execution order is always the same: 1 — Synchronous code runs first All regular code on the Call Stack executes immediately. 2 — Microtasks run second Promises, async/await — these run before anything else once the Call Stack is empty. 3 — Macrotasks run last setTimeout, setInterval, DOM events — these wait until ALL microtasks are done. This is why setTimeout with 0ms still runs after a Promise. The Promise is a microtask. setTimeout is a macrotask. Microtasks always win. Understanding this prevents real bugs in production — async state updates, race conditions, unexpected render order. Save this post for your next async debugging session. Have you ever been confused by JavaScript async order? Drop a comment below. #JavaScript #WebDevelopment #Frontend #SoftwareEngineering #AsyncJavaScript
To view or add a comment, sign in
-
-
15 JavaScript interview questions. DOM Manipulation & Events. Answer karo comments mein 👇 DOM Basics Q1. What is the DOM? Q2. What is the difference between querySelector and getElementById? Q3. What is the difference between textContent and innerHTML? Events Q4. What is an event listener and how do you add one? Q5. How do you remove an event listener? Q6. What is event bubbling? Q7. What is the difference between event bubbling and event capturing? Q8. What is e.stopPropagation() and when do you use it? Q9. What is e.preventDefault() and when do you use it? Q10. What is the difference between e.target and e.currentTarget? Event Delegation Q11. What is event delegation and why is it important? Q12. How does React use event delegation internally? Advanced Q13. What are synthetic events in React? Q14. Why should you avoid direct DOM manipulation in React? Q15. What is the difference between mouseenter and mouseover? Full answers + code on GitHub 👇 https://lnkd.in/dj72-XEi #JavaScript #JStoReact #InterviewPrep #WebDevelopment #Frontend #ReactJS #30DayChallenge #JavaScriptTips #FrontendDeveloper #100DaysOfCode
To view or add a comment, sign in
-
Day 9 – React Interview Journey 🚀 DOM: The Document Object Model is a tree structure of your webpage that browsers use to display and update content. Why Virtual DOM? The Virtual DOM was created to improve performance by minimizing direct updates to the real DOM. 💬 What’s one React concept you struggled with at first? Drop it below 👇 #Day9 #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #CodingJourney #InterviewPrep
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