pending: This is the initial state of Promise
fulfilled: Promise is said to be fulfilled when it is resolved
rejected: Promise is said to be rejected when we have some
error while resolving
Initially the promise will be in the pending state. As the consuming code is waiting for the result of producing code(either "resolve" or "reject") which is asynchronous in nature.
when the "if" condition becomes true, the promise gets resolved
after 2 seconds, now we can say the promise is fulfilled. The ".then" block of consuming code is executed, and the result will be logged to the console.
when the "if" condition becomes false, the promise gets rejected
after 2 seconds, now we can say the promise is in rejected state. The ".catch" block of consuming code is executed, and the result will be logged to the console.