Huck's youth likely means that he is more openminded to befriending Jim than most others in his society would be. Yet Huck has plenty of experience, and this is part of what allows his friendship with Jim to deepen over time.
Jim and Huck have a common goal, and this is part of what brings them together. Both are trying to escape the demons that await them at home, and they are willing to risk nearly anything to create a different future for themselves. Huck's Pap is a lousy excuse for a father; his drunkenness and greed leave little room for him to be a decent role model for Huck. In Jim, Huck sees something different from the abusive man he knows as a father; Jim is patient, loyal, and practical. Huck gravitates toward these qualities at least in part because they are the opposite of his father's influence.
Later in the novel, Huck realizes that the "correct" thing to do, by the standards of his society, would be to return Jim to Mrs. Watson. Instead, he decides to risk eternal damnation, the punishment he believes he might face, to try to help free Jim from slavery. Again, he makes this choice because of his experiences: he has seen the goodness in Jim. Huck has seen the life of slavery, albeit from a distance, and he doesn't want to return Jim to that life of confinement.
Huck's youth likely makes him more openminded toward Jim, but he is able to compare the experiences of his past with his father to the faithful friendship he develops with Jim. This contrast, together with their shared goal, forges a faithful friendship.