The village of Royston Vasey is best avoided: Locals include a sinister circus master who knocks on doors on the pretext of “looking for Dave” to kidnap housewives for his harem; the hideously deformed shopkeepers who feed visiting strangers to unseen offspring; and a demon butcher whose pies are filled with unmentionable “special stuff”.

I doubt that the gifted team behind The League of Gentlemen, a cult BBC comedy show that aired between 1999 and 2002, could pinpoint exactly why their brand of black humour worked. But it was truly, bizarrely, horribly funny.

That is the funny thing about funny things: It is hard to predict what will elicit a spontaneous vocal whoop. We laugh when we catch a witty one-liner but also when we are angry, nervous and confused. Comedy can emerge in the wake of tragedy; bedside vigils for a terminally ill friend turned into occasions for mirth as well as misery (we did try to remain solemn in front of the nurses). Politically incorrect jokes cause merriment for some, offence for others. Disturbingly, some murderers laugh before pulling the trigger.

Inappropriate laughter was identified last week by scientists as a possible early-warning sign of dementia. Frontotemporal dementia (FTD) is the most common cause of dementia in under-55s. Researchers noted that sufferers often laughed at banal things — like a barking dog — and that this altered sense of humour sometimes predated formal diagnosis by as much as nine years.

The idea that a misplaced chortle is a signpost to a decaying brain adds to the mystery of why we possess the capacity to be amused at all. The origin of laughter is, in fact, an ancient teaser for which science lacks a convincing punchline.

This much we do know: Laughter is found in all human societies and in chimpanzees and other apes. We first laugh as babies. These facts suggest it is evolved rather than learnt behaviour. Giggles tend to arrive unbidden, are hard to fake, and can be even harder to control. They can leave us breathless. Laughter is also infectious: Perhaps the most famous epidemic occurred in 1962 in Tanganyika (now Tanzania) among teenage schoolgirls and resulted in the temporary closure of 14 schools.

Beyond this, however, research into why we laugh is surprisingly scant. The American psychologist, Robert Provine, when he embarked on his own studies two decades ago, put it beautifully: “Given the universality of the sound, our ignorance about the purpose and meaning of laughter is remarkable.” So he and his undergraduate students went out and recorded people laughing in real life. Their empirical research showed that women laughed more than men, speakers laughed more than their audience and fewer than one-fifth of all chuckles were prompted by a joke. People were 30 times more likely to laugh when in company than when alone.

Professor Provine thinks this particular vocalisation is rooted in social bonding. Laughter, he says, punctuates ordinary conversations and oils sexual courtship: in personal ads, men tend to sell their GSOH (good sense of humour) to potential partners and women specifically request it.

Women may unwittingly use humour as a gauge of intelligence. Dr Camilla Clarke, from the University College London, Dementia Research Centre, who led the FTD study, points out that “humour ... puts demands on so many different aspects of brain function, such as puzzle solving, emotion and social awareness”.

Curiously, though, the “aha” that comes from solving a puzzle is not the same as the “ha-ha” of getting a joke, even if brain scanning experiments show that our neural reward circuits are triggered by both. Scott Weems, a cognitive neuroscientist, argues that laughing is an involuntary reaction to our resolution of a cognitive conflict. That incongruity is banished when we hear a punchline. It is actually a neuroscientific reworking of incongruity theory, a long-standing explanation of humour. Another is the relief theory: That we laugh to release tension (tickling causes laughter because an approaching tickler induces apprehension).

I am not sure, though, that this solves the “why” of laughter: Cryptic crosswords make my head throb with cognitive conflict, but they do not make me guffaw in the same way as this: “I just deleted all the German names from my phone. Now it’s Hans-free.” Darren Walsh’s wisecrack was voted the funniest joke at this year’s Edinburgh Fringe.

Hurrah that science cannot yet unveil the full neurological truth about humour: That would spoil the gag. And now, if you’ll excuse me, there’s a chap at the door who is looking for Dave.

— Financial Times

Anjana Ahuja is a science commentator.