Laughter is very complicated and there are lots of theories as to why it works.One theory is that laughter is supposed to be a reaction to feeling relieved, so jokes tend to be about something unexpected. When we realise that the unexpected thing isn’t dangerous, we are relieved and laugh.
To be honest, this doesn’t make much sense to me! But laughing is good for you so we should do it as often as possible!
I read a while ago that some scientists believe that laughter was around before language as a form of communication and it’s something we are born with and to a large extent can’t control. It’s thought of as a social activity (you’re more likely to laugh at something funny when other people are around you than when you are on your own) and it may have evolved as a method of easing tension in a group situation (which would have been very important for early humans who lived in small groups and had to get on with each other to survive)