🚀 Node.js Interview Question #9: Difference between setImmediate() and setTimeout() Both are used to schedule asynchronous execution, but they run in different phases of the Event Loop. 📌 setTimeout() Executes after a specified delay. setTimeout(() => { console.log("Timeout"); }, 0); 📌 setImmediate() Executes after the current I/O operations are completed. setImmediate(() => { console.log("Immediate"); }); 💡 Key difference: "setImmediate()" runs in the check phase, while "setTimeout()" runs in the timers phase of the event loop. #NodeJS #JavaScript #BackendEngineering
Node.js setImmediate() vs setTimeout() differences
More Relevant Posts
-
🚀 Day 12 of My Frontend Developer Interview Preparation Today I focused on one of the most important concepts in JavaScript — Promises and how to handle multiple async operations efficiently. 🔹 What I learned today: Promise chaining using .then() Handling errors with .catch() Promise methods: 👉 Promise.all() 👉 Promise.race() 👉 Promise.allSettled() 💡 Key Takeaways: Promise chaining helps in executing async tasks in sequence Promise.all() is useful when we need all results together (fails if one fails) Promise.race() returns the fastest result Promise.allSettled() gives results of all promises (whether resolved or rejected) 🔥 It was interesting to see how JavaScript handles multiple async operations and how we can control them efficiently. Every day I’m getting more comfortable with async concepts, which are very important for real-world applications and interviews. 📌 Next step: Practice more real-world questions based on Promises #Day12 #FrontendDeveloper #JavaScript #Promises #AsyncJavaScript #WebDevelopment #CodingJourney
To view or add a comment, sign in
-
🚀 Day 6 – Frontend Interview Series 🔥 Topic: Promises (Async JavaScript) 💡 What is a Promise? A Promise in JavaScript is an object that represents the result of an asynchronous operation (like API calls, timers, file reading). 👉 It has 3 states: Pending ⏳ Resolved (Fulfilled) ✅ Rejected ❌ 📦 Basic Example const myPromise = new Promise((resolve, reject) => { let success = true; if (success) { resolve("Task completed!"); } else { reject("Task failed!"); } }); myPromise .then((res) => console.log(res)) .catch((err) => console.log(err)); ⚡ Why Promises? 👉 To avoid callback hell 👉 To handle async code in a clean way 👉 Better readability & chaining #JavaScript #ReactJS #FrontendDeveloper #InterviewPrep #AsyncJS
To view or add a comment, sign in
-
⚛️ React Interview Question Why shouldn’t we mutate state directly in React? We write: state.user.name = "John"; setState(state); Looks fine. But UI may not update correctly. 🧠 Why? React checks reference, not deep values. If the reference doesn’t change, React thinks nothing changed. 👉Correct way setState({ ...state, user: { ...state.user, name: "John" } }); New reference → React updates. React doesn’t track changes. It tracks references. #ReactJS #FrontendDevelopment #JavaScript #ReactInterview
To view or add a comment, sign in
-
🚀 **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
-
💡 Daily React/JavaScript Interview Tip When explaining concepts like closures, state, or hooks—don’t just define them. Show how they solve a real problem. 👉 Instead of saying: “A closure lets a function access variables from its outer scope.” ✅ Say: “Closures are useful when you want to preserve state without exposing it globally—for example, creating a private counter inside a function.” Interviewers are not just testing what you know—they’re evaluating how you think and apply knowledge in real scenarios. 📌 Tip: Always pair your explanation with a quick use case or example. It instantly makes your answer stronger and more memorable. #ReactJS #JavaScript #WebDevelopment #TechInterviews #FrontendDevelopment
To view or add a comment, sign in
-
🚀 **React JS Interview Questions I Faced** Recently, I attended Infogain a React JS interview, and I wanted to share my experience along with some commonly asked questions. Hope this helps others preparing for frontend roles! 1. What is the difference between functional and class components? 2. What are React Hooks? 3. Explain useState and useEffect. 4. How does the Virtual DOM work? 5. What is a custom hook? 6. Difference between Axios and Fetch? 7. How do you optimize React application performance? 8. What is state lifting? 9. What are controlled and uncontrolled components? 10. What is props drilling? 11. How does React handle forms? 12. What is useContext and when do you use it? 13. What is React.memo? 14. Difference between useMemo and useCallback? 15. What are keys in React and why are they important? 💬 **Practical Task:** * Build a component with API integration * Handle loading and error states #ReactJS #FrontendDeveloper #InterviewQuestions #WebDevelopment #JavaScript #CodingInterview
To view or add a comment, sign in
-
Most people fail Node.js interviews not because they don’t know coding… But because they forget the basics. I found a Node.js revision sheet that covers 120+ important questions in one place. Honestly, this is the kind of resource you wish you had 1 day before your interview. 📌 It covers: • Event loop, async behavior and non-blocking I/O • Promises, async/await and real-world flow • Express, routing and middleware • Streams, buffers and core modules • JWT authentication and security basics • Scaling, clustering and system design The best part? It’s short, to the point, and perfect for quick revision. 📄 Check it out here: Save this now. You’ll thank yourself before your next interview. Follow Muhammad Nouman for more useful content #NodeJS #BackendDeveloper #InterviewPrep #JavaScript #Developers #LearnToCode #TechCareers
To view or add a comment, sign in
-
💡 Interview Insight: JavaScript Event Loop & Microtasks One of the interesting questions I was recently asked in an interview: 👉 “How would you move a task into the microtask queue in JavaScript?” This question dives deep into how the event loop works — something every frontend developer should understand beyond just theory. Here’s the essence: Microtasks have higher priority than macrotasks. They are executed right after the current call stack, before any rendering or next event loop tick. Common ways to push tasks into the microtask queue: Promise.resolve().then(...) queueMicrotask(...) MutationObserver (less common but interesting) ✨ Example: console.log("Start"); Promise.resolve().then(() => { console.log("Microtask"); }); console.log("End"); // Output: // Start // End // Microtask 🔍 Why it matters: Understanding this helps in: Writing predictable async code Debugging tricky timing issues Optimizing performance in real-world apps E-mail: panditdeshant@gmail.com #JavaScript #FrontendDevelopment #WebDevelopment #EventLoop #AsyncJavaScript #InterviewQuestions #Learning #OpenToWork
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
-
🧠 JavaScript Interview Question Here’s a small but tricky one that often comes up in interviews 👇 👉 Given an array: let array = [1, 2, 3, 4, 5]; 🚨 Step 1: Add extra properties to the array array.name = "Code"; array.role = "Frontend Developer"; for (let key in array) { console.log(key, ":", array[key]); } 👉 Output: 0 : 1 1 : 2 2 : 3 3 : 4 4 : 5 name : Code role : Frontend Developer 😮 Notice how for...in also loops through custom properties! ✅ Step 2: Print only original array values using hasOwnProperty for (let key in array) { if (array.hasOwnProperty(key) && !isNaN(key)) { console.log(array[key]); } } 👉 Output: 1 2 3 4 5 #JavaScript #FrontendDeveloper #ReactJS #CodingInterview #WebDevelopment
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