Huck learns many lessons throughout his journey on the Mississippi with Jim. The most important of these involve caring and moral responsibility.
Huck is a child who has never had a chance to develop a real bond with another human being. His Pap is a drunk who doesn't care if Huck lives or dies. Huck only knows how to use and manipulate another—the lesson he learned from Pap—or how to evade responsibility, the lesson he taught himself when trying to get away from the Widow Douglas and Miss Watson. Once Huck begins to spend every night with Jim, he falls back on his own habits at first and plays merciless tricks on Jim. When Jim scolds Huck for playing a trick on him, Huck begins to feel bad, realizing he has hurt another human being, even if Huck still sees the human being as "only" a slave.
Jim gives Huck the nurturing and care he has never had, and the two become inseparable companions. Through the time they spend together, Huck learns what it's like to have companionship and even love.
His twisted understanding of society's mores still tell him, however, that he is doing "wrong" to keep a slave from capture. It is only when Huck tears up the letter he has written to Miss Watson and emphatically says, "All right, I'll go to hell" that we see he has learned to defy the mores of a corrupt society, even if he naively believes this rebellion will send him to hell. He learns to listen to his true conscience, not the perverted mores of an unjust society.