Jokes often arise involuntarily, like dreams, and tend to be swiftly forgotten. From these similarities Freud inferred that jokes and dreams share a common origin in the unconscious. Both are essentially means of outwitting our inner 'censor'.
Jim Holt (2008). “Stop Me If You've Heard This: A History and Philosophy of Jokes”, p.70, W. W. Norton & Company
