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
Understanding Promise.allSettled() in JavaScript
More Relevant Posts
-
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
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 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
-
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
-
🔒 Advanced JavaScript — Day 5: Scope, Execution Context & Closures Today I studied one of the most important — and most misunderstood — concepts in all of JavaScript. Closures. I've heard this word thrown around in interviews, tutorials, and job descriptions for months. Today I finally sat down, understood it deeply, and built a real project using it: a fully configurable Toast Notification system. Here's everything I covered 👇 📌 Scope — Where Variables Live 📌 Execution Context & the Scope Chain 📌 Closures — The Real Magic 🪄 📌 The Toast Project — What It Does 📌 Why Closures Matter in Real Development Today was one of those days where a concept that seemed complex finally clicked completely. Closures aren't magic. They're just functions that remember where they came from. Day 6 tomorrow. The streak continues. 🔥 #AdvancedJavaScript #JavaScript #Closures #Scope #ExecutionContext #100DaysOfCode #LearnInPublic #WebDevelopment #Frontend #CodingJourney #BuildInPublic #ProjectBased #TechLearning
To view or add a comment, sign in
-
-
🚀 Day 9 of Frontend Developer Interview Preparation Today I explored some very important JavaScript concepts — setTimeout and Higher-Order Functions. ⏳ setTimeout Learned how JavaScript handles asynchronous behavior using the event loop. Even though we provide a delay, the execution depends on the call stack and callback queue — which makes it more interesting than it looks! 🔁 Higher-Order Functions (HOF) Understood how functions can take other functions as arguments or return them. This concept is widely used in JavaScript (like map, filter, reduce) and is possible because functions are treated as first-class citizens. 💡 Key Takeaways: JavaScript is single-threaded but handles async tasks efficiently setTimeout doesn’t guarantee exact timing — it depends on the execution flow Higher-Order Functions make code more reusable and powerful 📌 Consistency is the key — learning step by step and strengthening fundamentals. If you're also preparing for frontend interviews, feel free to connect or share your thoughts! #JavaScript #FrontendDevelopment #InterviewPreparation #100DaysOfCode #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
Revisiting some core JavaScript fundamentals while preparing for technical interviews. Today I revised the concept of Closures — one of the most important concepts in JavaScript. A closure can be understood as: Closure = Function + reference to the lexical environment in which that function was created. Example: function outer(){ let a = 10; function inner(){ console.log(a); } return inner; } let res = outer(); res(); // 10 Even after "outer()" finishes execution, "inner()" still remembers the variable "a". This happens because the inner function keeps a reference to the outer lexical environment. Inspired while revising JavaScript fundamentals from @GeeksforGeeks and @CoderArmy. #javascript #webdevelopment #frontend #softwareengineering #interviewprep
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
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