I think a lot comes from having the experience of doing stand-up comedy. It allows you to figure out the psychology of an audience; what things are funny and not.
Keenen Ivory Wayans Famously Quoted