Foil: “a foil is a character who contrasts with another character (usually the protagonist) in order to highlight particular qualities of the other character.” (This definition is from wikipedia, but as an English graduate, I can tell you it's accurate)
In Les Miserables, Jean Valjean and Javert are foils. Valjean is full of mercy. Javert is full of justice. Valjean believes people can change and change for the better. Javert doesn't. Valjean breaks laws. Javert goes above and beyond to keep them. Their differences are more obvious when they have each other for comparison.
Often you'll see the protagonist foils the antagonist, (and often they will share similar origins,) but foils can be any two characters.
Taking it Further—
While by definition, foils refer to two characters contrasting one another, you can take it further. You can use foils in other aspects of your story. You can foil settings, creatures, dialogue, relationships, and pretty much anything else. In Lord of the Rings, the elves, with their beauty and grace, foil the orcs—each is more striking because of the other. Do you want to create a stunning setting? Create a foul one to contrast it. The more prevalent the foul, the more beautiful and special the stunning.
Giving a Character Two Foils—
Another way to take this concept further is to give your character two foils and fit her in the middle of the two extremes. I can’t take the credit for this idea; I learned about it from my professor in my Shakespeare class, because Shakespeare used this method.
In Henry IV Part 1, Prince Hal is a character with two foils. On one side of him, there is Hotspur, who is obsessed with glory and honor, on the other side, there is Falstaff, who rationalizes that honor isn’t that important; after all, it doesn’t provide food or guarantee his life. Hal fits in the middle, and as such, the audience perceives him as “just right”--he is the perfect balance.
Like Hal, Frodo has two foils. While going to Mordor, he travels with Smeagol and Sam, who are opposites. Smeagol is obsessed, tormented, and consumed by the Ring. Sam, however, is free of the Ring’s power, having never held it. He sees the Ring for what it really is and regards Smeagol with disgust. Frodo fits in the middle. He relates to Smeagol, perceiving the creature as what he could become, and at times longs to keep the Ring. But Frodo is like Sam in his determination to destroy it. Sam and Smeagol help illustrate Frodo’s complexity.
(And as opposites, Hotspur and Falstaff, and Smeagol and Sam, foil each other as well.)
Be careful what direction you take your foils. For example, you wouldn’t want to make a woman look stronger by making all the men in the story complete idiots. So be smart about it.
So, I'm just wondering, what are everyone else's favorite foiling characters?