JavaScript Interview Question: What is Promise.all()? Answer: Promise.all() runs multiple promises in parallel and resolves when all succeed. Example: 𝘗𝘳𝘰𝘮𝘪𝘴𝘦.𝘢𝘭𝘭([𝘧𝘦𝘵𝘤𝘩𝘜𝘴𝘦𝘳𝘴(), 𝘧𝘦𝘵𝘤𝘩𝘗𝘰𝘴𝘵𝘴()]) .𝘵𝘩𝘦𝘯(([𝘶𝘴𝘦𝘳𝘴, 𝘱𝘰𝘴𝘵𝘴]) => { 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘶𝘴𝘦𝘳𝘴, 𝘱𝘰𝘴𝘵𝘴) }) Explanation: If any Promise fails, Promise.all() immediately rejects. Follow-up Interview Question: When should you use Promise.all()? Answer: When multiple independent async tasks can run simultaneously. #javascript #promises #AsyncProgramming #FrontendDevelopment
Understanding Promise.all() in JavaScript
More Relevant Posts
-
JavaScript Interview Question: What is Promise.allSettled()? Answer: Promise.allSettled() waits for all promises to finish regardless of success or failure. Example: 𝘗𝘳𝘰𝘮𝘪𝘴𝘦.𝘢𝘭𝘭𝘚𝘦𝘵𝘵𝘭𝘦𝘥([𝘱𝘳𝘰𝘮𝘪𝘴𝘦1, 𝘱𝘳𝘰𝘮𝘪𝘴𝘦2]) Explanation: It returns an array of objects describing each promise result. Follow-up Interview Question: When should you use Promise.allSettled() instead of Promise.all()? Answer: When you need results from all promises even if some fail. #javascript #promises #AsyncProgramming #WebDevelopment
To view or add a comment, sign in
-
JavaScript Interview Question: What are the states of a Promise? Answer: A Promise has three states: 1. Pending → initial state 2. Fulfilled → operation completed successfully 3. Rejected → operation failed Example: 𝘧𝘦𝘵𝘤𝘩("/𝘢𝘱𝘪") .𝘵𝘩𝘦𝘯(𝘳𝘦𝘴 => 𝘳𝘦𝘴.𝘫𝘴𝘰𝘯()) .𝘤𝘢𝘵𝘤𝘩(𝘦𝘳𝘳 => 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘦𝘳𝘳𝘰𝘳(𝘦𝘳𝘳)) Explanation: Once a Promise is fulfilled or rejected, its state becomes immutable and cannot change. Follow-up Interview Question: Can a Promise change state after it is fulfilled? Answer: No. Explanation: Once resolved or rejected, a Promise cannot transition to another state. #javascript #promises #AsyncProgramming #SoftwareEngineering
To view or add a comment, sign in
-
JavaScript Interview Question: What is the difference between Promises and Callbacks? Answer: Callbacks pass a function to execute after async operations. Promises represent the result of an async operation. Explanation: Promises provide: 1. better readability 2. error handling 3. chaining support Follow-up Interview Question: Why did callback hell occur? Answer: Because nested callbacks made code difficult to maintain. #javascript #AsyncProgramming #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 23/100 – #100DaysOfCode JavaScript Interview Questions (Advanced Concepts) Continuing with JavaScript fundamentals, today I reviewed some important interview questions that test a deeper understanding of how JavaScript works under the hood. 🔹 Hoisting Hoisting is JavaScript’s behavior where variable and function declarations are moved to the top of their scope before execution. var is hoisted with undefined, while let and const are hoisted but remain in the temporal dead zone. 🔹 Callback Function A callback is a function passed as an argument to another function, which is executed later. Commonly used in: -Asynchronous operations (API calls) -Event handling 🔹 Closure A closure is a function that remembers variables from its lexical scope even after the outer function has finished execution. This is heavily used in: -Data encapsulation -Maintaining private variables 🔹 Pass by Value vs Pass by Reference Pass by Value: A copy of the value is passed (Primitive types) Pass by Reference: A reference to the original object is passed (Objects, Arrays) Changes in reference types affect the original data, while primitive changes do not. Understanding these concepts is critical because they often separate beginners from intermediate developers in interviews. 23 days down, 77 more to go. #Day23 #100DaysOfCode #JavaScript #FrontendDevelopment #WebDevelopment #CodingInterview #MERN
To view or add a comment, sign in
-
JavaScript Interview Question: What is a Promise in JavaScript? Answer: A Promise is an object that represents the eventual completion or failure of an asynchronous operation. A Promise can be in three states: 1. pending 2. fulfilled 3. rejected Example: 𝘤𝘰𝘯𝘴𝘵 𝘱𝘳𝘰𝘮𝘪𝘴𝘦 = 𝘯𝘦𝘸 𝘗𝘳𝘰𝘮𝘪𝘴𝘦((𝘳𝘦𝘴𝘰𝘭𝘷𝘦, 𝘳𝘦𝘫𝘦𝘤𝘵) => { 𝘴𝘦𝘵𝘛𝘪𝘮𝘦𝘰𝘶𝘵(() => 𝘳𝘦𝘴𝘰𝘭𝘷𝘦("𝘋𝘰𝘯𝘦"), 1000) }) Explanation: Promises allow developers to handle asynchronous operations without deeply nested callbacks. They make async code easier to read and manage. Follow-up Interview Question: Why were Promises introduced in JavaScript? Answer: To solve problems like callback hell and better manage asynchronous workflows. #javascript #promises #AsyncProgramming #WebDevelopment
To view or add a comment, sign in
-
🚀 JavaScript Interview Must-Know: Closures Explained Simply If you’re preparing for a JavaScript interview, one concept you cannot ignore is Closures. 👉 What is a Closure? A closure is created when a function remembers variables from its lexical scope even after the outer function has finished executing. Sounds confusing? Let’s simplify 👇 function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 counter(); // 3 👉 What’s happening here? inner() function still has access to count Even though outer() has already finished execution This is called a closure 💡 Why Interviewers Love This Question? Because it tests: Scope understanding Memory behavior Real-world problem solving 🔥 Real Use Cases: Data hiding (private variables) Function factories Event handlers Callbacks & async code 👉 Pro Tip: Closures are heavily used in frameworks like React (hooks work on similar concepts) 💬 If you’re learning JavaScript for interviews, master this concept — it appears in almost every technical round. #JavaScript #WebDevelopment #MERNStack #Frontend #CodingInterview #100DaysOfCode #Developers #LearnToCode #IrfanMeraj
To view or add a comment, sign in
-
-
JavaScript Interview Question I Faced Recently 💻 One of the questions I forgot to share earlier: Problem: Convert the array "["a","1","b","2","c","3"]" into the object "{ a: 1, b: 2, c: 3 }" My Approach: const arr = ["a","1","b","2","c","3"]; const result = {}; for (let i = 0; i < arr.length; i += 2) { result[arr[i]] = arr[i + 1]; } console.log(result); Idea: The array contains alternating key–value pairs. So we iterate through the array by 2 steps and assign: - "arr[i]" → key - "arr[i+1]" → value Simple but a good way to test JavaScript fundamentals and array manipulation. Have you seen similar questions in interviews? 🤔 #JavaScript #FrontendDevelopment #CodingInterview #WebDevelopment #Learning
To view or add a comment, sign in
-
🎯 JavaScript Interview Prep — Let’s See Where You Stand If you’re preparing for a JS interview… Don’t just read. Answer these without Googling. Let’s test real understanding 👇 🧠 𝟭. 𝗪𝗵𝗮𝘁 𝘄𝗶𝗹𝗹 𝘁𝗵𝗶𝘀 𝗹𝗼𝗴 — 𝗮𝗻𝗱 𝘄𝗵𝘆? 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘢); 𝘷𝘢𝘳 𝘢 = 10; Bonus: Would the answer change with `let`? ⚡ 𝟮. 𝗪𝗵𝗮𝘁’𝘀 𝘁𝗵𝗲 𝗼𝘂𝘁𝗽𝘂𝘁 𝗼𝗿𝗱𝗲𝗿? 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨("𝘚𝘵𝘢𝘳𝘵"); 𝘴𝘦𝘵𝘛𝘪𝘮𝘦𝘰𝘶𝘵(() => 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨("𝘛𝘪𝘮𝘦𝘰𝘶𝘵"), 0); 𝘗𝘳𝘰𝘮𝘪𝘴𝘦.𝘳𝘦𝘴𝘰𝘭𝘷𝘦().𝘵𝘩𝘦𝘯(() => 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨("𝘗𝘳𝘰𝘮𝘪𝘴𝘦")); 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨("𝘌𝘯𝘥"); If you can’t confidently explain this, revise the Event Loop. 🔥 𝟯. 𝗪𝗵𝗮𝘁’𝘀 𝘄𝗿𝗼𝗻𝗴 𝗵𝗲𝗿𝗲? 𝘧𝘰𝘳 (𝘷𝘢𝘳 𝘪 = 0; 𝘪 < 3; 𝘪++) { 𝘴𝘦𝘵𝘛𝘪𝘮𝘦𝘰𝘶𝘵(() => 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘪), 100); } Why does it print what it prints? How would you fix it? 🧩 𝟰. 𝗘𝘅𝗽𝗹𝗮𝗶𝗻 𝘁𝗵𝗶𝘀 𝗶𝗻 𝘆𝗼𝘂𝗿 𝗼𝘄𝗻 𝘄𝗼𝗿𝗱𝘀: What’s the difference between: 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘵𝘦𝘴𝘵() {} 𝘤𝘰𝘯𝘴𝘵 𝘵𝘦𝘴𝘵 = () => {}; Not syntax. Think: `this`, hoisting, constructors. 🚀 𝟱. 𝗪𝗵𝗮𝘁 𝗵𝗮𝗽𝗽𝗲𝗻𝘀 𝗵𝗲𝗿𝗲? 𝘤𝘰𝘯𝘴𝘵 𝘰𝘣𝘫 = { 𝘯𝘢𝘮𝘦: "𝘑𝘚" }; 𝘤𝘰𝘯𝘴𝘵 𝘯𝘦𝘸𝘖𝘣𝘫 = 𝘰𝘣𝘫; 𝘯𝘦𝘸𝘖𝘣𝘫.𝘯𝘢𝘮𝘦 = "𝘑𝘢𝘷𝘢𝘚𝘤𝘳𝘪𝘱𝘵"; 𝘤𝘰𝘯𝘴𝘰𝘭𝘦.𝘭𝘰𝘨(𝘰𝘣𝘫.𝘯𝘢𝘮𝘦); 📌 Be honest — how many did you answer confidently without guessing? Drop your answers in the comments 👇 Let’s see who actually understands JavaScript… and who just uses it. #javascript #frontend #techinterview #webdevelopment #codingchallenge #DAY72
To view or add a comment, sign in
-
Javascript Event Loop - One of the Most Asked Interview Questions If you’ve ever prepared for a frontend interview, you’ve definitely come across this question: 👉 “How does the JavaScript Event Loop work?” Understanding the Event Loop is crucial because it explains how JavaScript handles asynchronous operations despite being single-threaded. 💡 In simple terms: JavaScript executes code using a call stack. Async tasks (like setTimeout, Promises, API calls) are handled by Web APIs Once completed, they move to callback queues. The Event Loop continuously checks and pushes tasks back to the call stack when it's empty. ⚡ Key concepts every developer should know: Call Stack Callback Queue Microtask Queue (Promises > setTimeout priority) Execution Order 🎯 Mastering this concept not only helps in interviews but also improves your ability to write efficient, non-blocking code. I’ve created a simple explanation (with examples) to make this concept easy to understand 👇 #JavaScript #Frontend #WebDevelopment #EventLoop #InterviewPrep #AsyncProgramming
To view or add a comment, sign in
-
JavaScript Interview Question: What is Promise.race()? Answer: Promise.race() returns the result of the first promise that settles (resolved or rejected). Example: 𝘗𝘳𝘰𝘮𝘪𝘴𝘦.𝘳𝘢𝘤𝘦([𝘢𝘱𝘪𝘊𝘢𝘭𝘭(), 𝘵𝘪𝘮𝘦𝘰𝘶𝘵()]) Explanation: It is useful when implementing timeouts for API requests. Follow-up Interview Question: What happens if the first Promise rejects? Answer: The entire Promise.race() rejects immediately. #javascript #promises #AsyncProgramming #SoftwareEngineering
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