Humor arose as a group-defense mechanism. Say, you were the head ape of a group of apes. Your group of apes encountered a threat, like another group of apes, or a tiger. By telling a few jokes, the head ape could get his subordinate apes to force stale air from their lungs and charge up their bloodstream with more oxygen. Human laughter is also rather loud and barking, which can be used to make the group seem like a larger threat.
We see the same mechanism happen to ghetto apes all the time.