Bird
0
0

What will be the output of this Angular code?

medium📝 Predict Output Q4 of 15
Angular - RxJS and Observables Fundamentals
What will be the output of this Angular code?
const promise = new Promise(resolve => {
  console.log('Promise started');
  resolve('Done');
});
promise.then(value => console.log(value));
console.log('After promise');
APromise started<br>After promise<br>Done
BPromise started<br>Done<br>After promise
CAfter promise<br>Promise started<br>Done
DDone<br>Promise started<br>After promise
Step-by-Step Solution
Solution:
  1. Step 1: Understand Promise executor execution

    The executor function runs immediately, so 'Promise started' logs first.
  2. Step 2: Understand Promise.then timing

    Then callback runs asynchronously after current synchronous code, so 'After promise' logs before 'Done'.
  3. Final Answer:

    Promise started
    After promise
    Done
    -> Option A
  4. Quick Check:

    Promise executor sync, then async [OK]
Quick Trick: Promise executor runs sync; then runs async [OK]
Common Mistakes:
MISTAKES
  • Assuming then runs immediately
  • Confusing order of console logs
  • Thinking all code runs asynchronously

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes