It works for two reasons, one of which was bit surprising to me:
(1) It is a nasty irritant (2) the "SWOOSH" noise surprises the bear.

I've seen a couple of videos where the bear starts turning before the spray actually hits him. Maybe it is a learned behavior from a skunk encounter - just a guess.

Bear spray has a better track record than handguns. Absolutely I trust my life to it. And it gives you a non-lethal way to deal with somebody's dog.

I'm not knocking hog-legs - they work. But $50 makes more sense for somebody who is only going to wander into the back country rarely and doesn't have the means or interest to shell out $800 - $1200 for a revolver and then the $ and time for 1k rounds of practice.