Are sitcom characters "joking"?

I'd be interested to get everybody's opinion on this. For basically my whole life, I've always thought of the dialogue on most sitcoms to only be funny to us, the viewers, the joke often being, "It's silly for this person to talk or act this way, and silly that the person they're talking to thinks it's normal. These are weird people." After all, the other characters almost never laugh, nor do the characters saying the lines. The best example I can think of is It's Always Sunny In Philadelphia​. This is an easy one because the characters are so completely delusional and unable to act like normal human beings, that it's obvious they're all being serious when they say the things that make us laugh. That's what makes it funny.

Now, there are other shows where it's quite obvious that the characters are cracking jokes at each other and that they find them funny (like Roseanne for example). She'll make fun of somebody, and you can tell that the other character understood the joke, whether they thought it was funny or not. But the "funny" of Jackie for example is that she's not trying to be funny. She's just crazy, etc and in this case, it seems like it only makes the viewers laugh, and the other Conners just find her annoying.

What I would call a more subtle overall example is Doug on King of Queens saying ridiculous stuff to get out of trouble, and Carrie responding in an annoyed or angry manner. He is never smiling or laughing when he's saying ridiculous things, so I've always thought of them as being his very earnest attempt to sell whatever outlandish lie he's trying to get away with, the funny part being that he actually believes it will work. Only recently has it occurred to me that sometimes the characters (Doug in this example) might just be acting silly on purpose to try to diffuse the situation with humor. That's just what comes to mind but I'm sure you guys can imagine these circumstances in a lot of shows.

Not sure if any of this is making sense, but if so I'd love to hear you examples.

TLDR: overall are sitcom characters "aware" or "trying" to be funny, or are we laughing at them exactly BECAUSE they're taking themselves seriously, and it's ridiculous? For me until recently I've always mostly thought of it to be the latter, and now I'm having second thoughts that I just haven't been smart enough to "get it" all these years.