When you are depressed and anxious, the last thing you would want to hear is a long lecture on mental health and the 'positive thinking' cliched advice. There is a funny saying I found somewhere on the internet - "Never in the history of being anxious has one been less anxious by being told to be less anxious." This in itself speaks the truth of the situation.
Hence, rather than saying anything to the person who is in despair, the alternately wise thing would be to encourage them to speak up about their feelings and make them comfortable with the fact that you are all ears. When you are depressed, you cannot easily trust people. Depression de facto makes you unwilling to share whatever you are going through for the fear of being judged, thought lowly or being ridiculed. To break this barrier, if we genuinely want to help someone in despair, we have to create an environment such that the person in question finds it naturally comfortable to open up about his/her feelings, insecurities and vulnerabilities. Only by making them express what they are exactly going through, we can start to think of ways to help them.
Even if this seems a difficult task, once we make them open up, then we can get cues to what can be the things that we can then say/convey to them to make them feel better. On the other hand, it is necessarily not needed to be verbally expressed as well. Sometimes, even symbolic gestures could mean a lot. For example if someone is in despair because they just lost someone they loved, we may just give them a silent company and make some good hot beverage for them. We can lend them our shoulders to cry, so to speak.
There might not be a magic word or a sentence that heals, but there can be a combination of gestures and behaviours that we can use to help whoever in our surrounding is anxious/depressed.