Promise States: Pending, Fulfilled, Rejected

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