Foreshadowing or guessing ahead is a literary device by which an author hints what is to come. It is used to avoid disappointment, and sometimes used to arouse readers.
A hint that is designed to mislead the audience is referred to as a red herring. A similar device is the flashforward (also known as prolepsis). However, foreshadowing only hints at a possible outcome within the confinement of a narrative. A flashforward is a scene that takes the narrative forward in time from the current point of the story in literature, film, television, and other media.
—Frodo: What a pity that Bilbo did not stab that vile creature [Gollum], when he had a chance!
—Gandalf: Pity? It was pity that stayed his hand. [...] Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement. For even the very wise cannot see all ends. [...] My heart tells me that he has some part to play yet, for good or ill, before the end; and when that comes, the pity of Bilbo may rule the fate of many – yours not least.
This conversation foreshadows the fact that later in the story Frodo himself pities Gollum and is unable to kill him. He has a last-minute change of heart against doing so. Gollum then inadvertently makes it possible to destroy the Ring, which is the whole point of Frodo's and the rest of the central characters' quest.
“Keep him!” she gasped. “He came naked, by night, alone and very hungry; yet he was not afraid! Look, he has pushed one of my babes to one side already. And that lame butcher would have killed him and would have run off to the Waingunga while the villagers here hunted through all our lairs in revenge! Keep him? Assuredly I will keep him. Lie still, little frog. O thou Mowgli –for Mowgli the Frog I will call thee–the time will come when thou wilt hunt Shere Khan as he has hunted thee.”
Foreshadowing is used in much of the works of John Steinbeck. In Of Mice and Men, Lennie accidentally kills a mouse, a puppy dog and finally Curley's Wife. This foreshadows his own death. When Carlson kills Candy's Dog, Candy told George, "I ought to of shot that dog myself" making George later chose to kill Lennie himself to save him from dying by the hands of a stranger. Doing it the way that Carlson did it was for the best because, "He won't even feel it." 
Foreshadowing can be carried out by characters predicting the future.Cassandra in The Iliad has the explicit ability to foresee the future and make a prophecy. She predicts that her son will come to a bad end[which?] if he doesn't change his ways or character.[how?] Similarly, omens, such as breaking a mirror, can be used to foreshadow bad luck.