To protect ourselves with defense mechanisms that ensure our safety in the world. Toxic personalities wear masks to hide their true self.
Projection has made its way into the general lexicon, it’s a defense mechanism. A person finds it painful to own the knowledge they have for example selfish; they call others selfish because they retain the good attributes and project their flaws on others.
Reaction formation is another defense mechanism, dealing with psychic pain by transforming that pain into the opposite, often humor. It’s the psyche’s way of protecting itself, to diffuse the anguish by flipping it.
A person who masks depression with humor is defending. The person may be defending against themselves feeling pain or against being shamed by others for sad feelings. It's an attempt to make it better, to lessen the pain, to minimize, to transform, to project on someone else.