For most bears, but not those in the grizzly family (or at least it MIGHT work, but it isn't 100%)...
When I lived in Alaska (Kodiak island to be exact), certainly had more than my share of bear encounters...and I was just a kid. Man, we were dumb. It's amazing we're still alive.
Once, we played with some cubs. We heard momma, but we got out of there before we actually saw her. (guessing she smelled us).
Another time, we were picking salmonberries on a hillside, when one came to the top of the hill (dad was running down the hill carrying his rifle). It actually reared up, but the hill was too steep for it to come down, giving us time to get in the car.
Then, my brother and his friends got cornered on the side of a rocky cliff. I actually had to run back home and get my shotgun (they were stuck there for about an hour or so...one determined bear). Just to scare it off. Luckily, where the bear was, and my brother was, there was no way for the bear to reach them, or me down on the ground. (it was a good 50 feet drop or more).
Only other time, we were fishing, and saw two bears further down the creek. We had plenty of time to just leave before they got interested in us. Luckily, the salmon were running, so I'm not even sure they saw us.
Bottom line, best bear defense....get somewhere the bear isn't, or cannot go.....