Bear spray is a non-lethal spray that should be used to deter aggressive bears. It temporarily reduces the bears’ sense of smell and sight, and allows you to quickly leave the area. There is also proof that a bear who is strayed will be less likely to approach humans in the future, thus reducing the number of bears that are killed by people using self-defense.
Bear spray should be kept in a easy-to-access location, like a hip holster, or side-pocket of a backpack, that way you can use it on demand if needed. And when aiming, try to shoot it at the bear’s feet, because it creates a cone of spray. But don’t think too hard, if a bear is charging you, just spray in the space between you.
You can watch a video about how to use bear spray here. It never hurts to be prepared for bear country.