In TV shows, producers may want to keep the ending of an episode a secret, even if it means keeping it from the stars themselves. In such a case, they will usually film more than one ending and not tell the cast which one will be used.