Self-esteem is the perceived value that one has of oneself and apparently for other people.
It is generated by your own goals and by the (apparent) expectations of others.
The midpoint-mechanics play an important role here. Because: Everyone wants to have a good feeling about themselves.
If something occurs that could affect it, it tries to reinterpret it so that good self-esteem is maintained.
People are guided by inherited or learned values. These are goals that move you, that you want to achieve in order to be emotionally satisfied.
If you e.g. the goal is in itself - and basically everyone have it - to be recognized by others, and if this is not the case, then you will make an effort to achieve this goal in order to have a good self-esteem again.
The resulting positive feeling is an important driving point in people.
Likewise, the ideals that you have in yourself as goals.
Values that trigger corresponding feelings - such as wrong goals - may be transformed through learning by generating a new goal. Or, as I said before, to see it positively or to deny it via the midpoint-mechanic.
Especially harmful to self-esteem is one's own condemnation; being angry with oneself, cursing oneself when one has done something wrong, etc. It can be attenuated or avoided by saying: What happened, had to happen, how it happened.
You get a particularly good sense of self-worth when you have overcome yourself (i.e. goals that served as obstacles to your current intended goal).