The origin of the Jack o Lantern:
The story of the carved vegetable as a lantern comes in many variants and is similar to the story of Will-o’-the-wisp retold in different forms across England, Wales, Scotland and Ireland. An old[year needed] Irish folk tale tells of Stingy Jack, a lazy yet shrewd farmer who uses a cross to trap the Devil. One story says that Jack tricked the Devil into climbing an apple tree, and once he was up there Jack quickly placed crosses around the trunk or carved a cross into the bark, so that the Devil couldn’t get down. Another tale says that Jack put a key in the Devil’s pocket while he was suspended upside-down.
Another version of the story says that Jack was getting chased by some villagers from whom he had stolen, when he met the Devil, who claimed it was time for him to die. However, the thief stalled his death by tempting the Devil with a chance to bedevil the church-going villagers chasing him. Jack told the Devil to turn into a coin with which he would pay for the stolen goods (the Devil could take on any shape he wanted); later, when the coin/Devil disappeared, the Christian villagers would fight over who had stolen it. The Devil agreed to this plan. He turned himself into a silver coin and jumped into Jack’s wallet, only to find himself next to a cross Jack had also picked up in the village. Jack had closed the wallet tight, and the cross stripped the Devil of his powers; and so he was trapped.
In both folktales, Jack only lets the Devil go when he agrees never to take his soul. After a while the thief died, as all living things do. Of course, his life had been too sinful for Jack to go to heaven; however, the Devil had promised not to take his soul, and so he was barred from hell as well. Jack now had nowhere to go. He asked how he would see where to go, as he had no light, and the Devil mockingly tossed him an ember that would never burn out from the flames of hell. Jack carved out one of his turnips (which were his favorite food), put the ember inside it, and began endlessly wandering the Earth for a resting place. He became known as "Jack of the Lantern", or Jack-o’-Lantern.
The term jack-o’-lantern is in origin a term for an ignis fatuus or will-o’-the-wisp in English folklore, used especially in East Anglia, its earliest known use dating to the 1660s. The application of the term to carved pumpkins in American English is first attested in 1834.
Jack-o-Lanterns were also a way of protecting your home against the Undead. Superstitious people used them specifically to ward away vampires. They thought this because it was said that the Jack-o-Lantern’s light was a way of identifying vampires and, once their identity was known, they would give up their hunt for you.