Depression must serve some kind of purpose for humans, else it wouldn't be around. After eons of evolution, the traits most necessary for our survival have arisen through natural selection. If depression was a pure detriment to our survival, humans prone to it should not have had success passing on their genes. Yet, depression is alive and well, so what purpose might it serve?
Perhaps anxiety can help give us an answer. One theory on the purpose of anxiety is that it makes us vigilant; it helps us keep an eye open for predators. Back in the early days of the Homo genus, we'd be on the lookout for that lion, avoid its location, live another day, and pass on our genes eventually. Even now, anxiety can help us spot an unsafe situation and steer away from it.
The causes of depression are a mystery as yet unsolved. Ask people what causes depression, and you'll get a variety of answers, but one I've often heard and used myself was: "Chemical imbalance in the brain." In theory, antidepressant medication can help bring the balance back. But, depression is a bit more complicated than simply restoring some kind of balance. Researchers still don't have all the answers, but they are learning more about the complexity of emotions.
Two articles helped me understand some of these biological complexities; they are listed at the end of this post. What caught my attention was how little we know about the science behind depression. Though we have learned much and have some good ideas to explore concerning depression's mechanisms, we are still very much in the dark. Some things these articles pointed to as biological explanations of depression: