A jack-o’-lantern (formerly also known as a Jack o’ the lantern) is typically a carved pumpkin. People have been making jack o’lanterns at Halloween for centuries.
An old Irish folk tale tells of Stingy Jack, a lazy yet astute farmer who uses a cross to trap the Devil. One myth says Stingy Jack invited the Devil to have a drink with him and then tricked the Devil because he was too stingy to pay for his drink. He convinced the Devil to turn himself into a coin that Jack could use to buy their drinks. Once the Devil did so, Jack decided to keep the money and put it into his pocket next to a silver cross, which prevented the Devil from changing back into his original form.
Jack eventually freed the Devil, under the condition that he would not bother Jack for one year and that, should Jack die, he would never claim his soul. The next year, Jack tricked the Devil again by convincing him into climbing an apple tree, once he was up there Jack quickly placed crosses around the trunk or carved a cross into the bark (Another version of the folklore says that Jack put a key in the Devil’s pocket while he was suspended upside-down), so that the Devil couldn’t get down until the Devil promised Jack not to bother him for ten more years.
Before the ten years were up, Jack died. Of course, his life had been too sinful for Jack to go to heaven (some believe he was a thief) and the Devil had promised not to take his soul, so he was barred from hell as well. Jack’s soul was doomed to wonder in darkness with no place of rest. 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 (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”.
Another commonly told version of lore is that Jack tricks the Grim-Reaper into giving him eternal life, and in exchange, the reaper takes his head to hell with him. Jack then wanders the earth using a carved pumpkin for a head.
Despite the colorful legends, the term jack-o’-lantern originally meant a night watchman, or man with a lantern, with the earliest known use in the mid-17th century.
There are hundreds of other stories and variations on the origin of the jack-o’-lantern but I think nowadays people carve pumpkins for the fun of it, although it is still widely believed (if only jokingly) that placing a carved pumpkin in your yard on All Hallows’ Eve will keep the evil spirits away.