I won't pretend to be an expert, but I have noticed a few things that make the good jokes stand out from the bad.
1. Characters in a comedy don't know they're funny, and they don't usually try to be.
I'm sitting here as I type this in front of my TV watching, as I do most nights, The Big Bang Theory. It's one of the top rated comedies on television, and for good reason -- it's really funny, and it's got really interesting and funny characters. But have you noticed something about the characters in sitcoms and even a lot of movies? They rarely, if ever, laugh along with the audience. That's because they're not trying to be funny.
If you've ever watched the show, you know that the most unintentionally funny character is probably Sheldon Cooper. Most of us love watching Sheldon fumble his way through life and social situations, even though we would probably stay as far away from his as possible were he a real person. Sheldon sees himself as decidedly un-funny, and his attempts at humor (and inappropriate reactions to other people's humor) are most of the show's charm.
2. Comedy is all about the unexpected.
The other night, I watched another Big Bang episode in which the guys are taking part in a robot competition. They build a rather unruly robot that ends up crashing through their door -- right at the moment that Penny is walking up the steps, having a normal phone conversation. Penny, caught unawares, goes from talking about her Saturday night plans one second to screaming her head off the next.
There's a YouTube video floating around on the internet that was created by PineSol. You know, the company whose commercials feature the proverbial "pine sol lady." The people featured in the video, commonly known as the "pine sol lady prank" (at least that's what came up when I googled it), think they're part of a routine product test until...well, just watch.
We laugh at that because it's unexpected. Sure, we know after a minute that the pine sol lady is going to jump out and scare the daylights out of these people. But they don't expect it, and consequently go from calm to hysterical in a nanosecond.
3. Something about what's funny rings true to life.
Like most of the American female population under 30, I absolutely love Mean Girls. The reason I think it's so popular and has (so far) stood the test of time is that it's much more believable than other teen movies. All of the sneaking around, talking about friends behind their back and being nice to their faces? That's a much more accurate portrayal of how girls often treat each other than the movies where a popular girl confronts a lowly wallflower. Mean Girls is funny because it's true.