O. Henry uses a variety of literary devices throughout his classic short story "The Gift of the Magi," first published in 1905, which has been adapted into many films—as early as 1909—and into plays and television programs.
Allusions—references to literature, people, and legends outside the story—in "The Gift of the Magi" begin with the title itself, which refers to the three magi, the three wise men or three kings "who brought gifts to the Babe in the manger." The story also contains other allusions to King Solomon and to the Queen of Sheba.
Had the Queen of Sheba lived in the flat across the airshaft, Della would have let her hair hang out the window some day to dry just to depreciate Her Majesty's jewels and gifts. Had King Solomon been the janitor, with all his treasures piled up in the basement, Jim would have pulled out his watch every time he passed, just to see him pluck at his beard from envy.
This paragraph also includes the imagery, or visualization, of Della's hair hanging out of the window, the Queen of Sheba envying Della's hair from "the flat across the airshaft," and King Solomon plucking his beard at the sight of Jim's watch.
The exaggerated reactions of the Queen of Sheba to Della's hair and of King Solomon to Jim's watch, which O. Henry uses for humorous effect, are also examples of hyperbole.
There's an allusion to Della as "a Coney Island chorus girl"—a reference to the amusement park in Brooklyn, New York, which is famous for amusement rides, hot dogs, and saltwater taffy—after she has her hair cut.
There's also a simile, "like a Coney Island chorus girl," using "like" to compare Della to the short-haired female singer-dancers who entertained there.
"Della's beautiful hair fell about her, rippling and shining like a cascade of brown waters" and "Della leaped up like a little singed cat" are also examples of similes using "like." "Jim stopped inside the door, as immovable as a setter at the scent of quail" is a simile that uses "as" instead of "like" to make the comparison.
Other examples of imagery in the story include the phrase "beautiful combs, pure tortoise shell, with jewelled rims," and this image of Della:
On went her old brown jacket; on went her old brown hat. With a whirl of skirts and with the brilliant sparkle still in her eyes, she fluttered out the door and down the stairs to the street.
O. Henry also includes what he calls "the hashed metaphor," the indirect comparison of dissimilar things, when he says, "and the next two hours tripped by on rosy wings" while Della shops for a gift for Jim. O. Henry also uses metaphor in his comparison of Della and Jim to the magi.
The phrases "sobs, sniffles, and smiles, with sniffles predominating" and "sudden serious sweetness" are examples of alliteration, which is the repetition of the same or similar sounds—such as the "s" in these examples—at the beginning of words that appear close together. This kind of alliteration is referred to as consonance, since the sound that's repeated is a consonant sound. (Assonance is the repetition of vowel sounds.)
Foreshadowing—presenting hints or clues of future happenings in the story—occurs throughout the story and includes O. Henry's repeated emphasis on Della's hair and Jim's watch, Della's purchase of the watch fob, and Jim's purchase of the hair combs.
"Jim was never late" is an example of foreshadowing, which raises the question of why Jim was late, which is answered later in the story.
The recurring foreshadowing helps to highlight the irony in the story. Dramatic irony occurs when the reader knows something that one or more characters in the story doesn't know. The reader knows that Della sold her hair, which Della has already foreshadowed will be quite a surprise for Jim when he comes back home.
Situational irony occurs when something unexpected happens, which is the surprise for the reader of the gifts that Della and Jim buy for each other and the surprise of Jim selling his watch to buy the combs that he gives to Della.
Della's initial reaction to the combs is also situational irony.
And then an ecstatic scream of joy; and then, alas! a quick feminine change to hysterical tears and wails.
The ending of the story is also ironic. Instead of being upset about getting presents that they can't use and regretting selling their hair and watch to buy gifts for each other, Jim and Della simply accept the situation as it is and sit down to have dinner, understanding that their love for each other is more valuable than any material possession or gift.