Let’s start with the question of why someone working at a grocery store checkout should wear gloves. Imagine they were not. A customer with COVID-19 comes in, touches all their groceries, then the checkout person touches them. Virus particles could transfer. Then they touch the groceries of the next person; another transfer. These all represent possible infections, so this is a way we’d see virus spread.
How to break the cycle? Well, one way is for the store clerk to wash or sanitize their hands between customers, killing any virus particles. An alternative would be for them to use a pair of gloves, and throw them out between customers. The key is that the gloves must be thrown out between customers. Just wearing gloves alone will not prevent the scenario above, you need new gloves for each person.
We can ask how this extends to you – should you wear gloves while (say) grocery shopping? During the shopping, you could be exposed to virus particles, and they could get on your hands. If you wash your hands or sanitize them after shopping and before you touch your face, this will avoid infection. You could also wear gloves and then either throw them away after shopping or wash them.
However: it is easy to use gloves wrong. If you wear the gloves, and then end up touching them with your bare hands while taking them off, you could be exposed. If you save the gloves without washing them, in principle the virus could survive (this is less likely, depending on how often you shop). Gloves are, in other words, not a substitute for hand washing.