Slide 1

Promises in JavaScript — The KFC Burger Analogy

Image 1 Image 2 Image 3
We’ll learn Promises through a fast-food story.
Slide 2

Producer vs Consumer

Split scene: kitchen (producer) and customer waiting (consumer) Kitchen produces, customer consumes.
Slide 3

Promise Object = Order Slip

Close-up of an order slip representing the Promise object
const order = new Promise((resolve, reject) => {
  // kitchen prepares burger here
});
The slip is the promise object.
Slide 4

Pending State

Kitchen busy and customer waiting with a ticking clock
// still preparing… no resolve/reject yet
// [[PromiseStatus]] = 'pending'
// [[PromiseValue]] = undefined
Waiting is the pending state.
Slide 5

resolve() — Success

Chef presenting a tray with a ready burger
resolve("🍔 Zinger Burger ready!");
// [[PromiseStatus]] = 'resolved'
// [[PromiseValue]] = "🍔 Zinger Burger ready!"
Order fulfilled.
Slide 6

reject() — Failure

Chef with an Out of Stock sign and empty tray
reject("❌ Burger out of stock!");
// [[PromiseStatus]] = 'rejected'
// [[PromiseValue]] = "❌ Burger out of stock!"
Order failed.
Slide 7

then() and catch()

Split: happy eating on success, refund on failure
order
  .then(msg => console.log("SUCCESS:", msg))
  .catch(err => console.error("ERROR:", err));
Respond to both outcomes.
Slide 8

finally()

Customer exiting the restaurant; session wrap-up
order
  .then(handleSuccess)
  .catch(handleError)
  .finally(() => console.log("🧾 Thanks for visiting KFC!"));
Always run closing actions.
Slide 9

React Example (API Call)

Laptop with code editor showing a fetch call; fast-food ambience
import { useEffect, useState } from "react";

export default function Users() {
  const [data, setData] = useState([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState("");

  useEffect(() => {
    let cancelled = false;

    async function load() {
      try {
        setLoading(true);
        setError("");
        const res = await fetch("https://jsonplaceholder.typicode.com/users");
        if (!res.ok) throw new Error("HTTP " + res.status);
        const json = await res.json();
        if (!cancelled) setData(json);
      } catch (e) {
        if (!cancelled) setError(String(e.message || e));
      } finally {
        if (!cancelled) setLoading(false);
      }
    }

    load();
    return () => { cancelled = true; };
  }, []);

  // render UI… (loading/error/data)
}
Promises power async React.
Slide 10

Summary

Summary collage of kitchen, order slip, customer, and arrows
new Promise(/* kitchen work */)
  .then(/* eat burger */)
  .catch(/* refund path */)
  .finally(/* go home */);
From order slip to outcome.