Many people have made the point that you need to know what type of bear. In general this can be done by knowing where you are going. In Washington State it is estimated there are only about 20 brown bears (Grizzlies). This number fluctuates as most of the bears have quite large territories that include part of Canada.
Black bears are responsible for a higher percentage of injuries and some deaths primarily because they are so wide spread. When you see a black bear the best thing to do is make lots of noise and through rocks or sticks at it. With a brown bear the stakes are higher and the rules change slightly. For all bears a general rule is not to run. You can back away slowly but if the bear starts to come closer you could be luring it to you. In that case, hold your ground.
Other than polar bears, humans are not typically food for bears. When they encounter you, they are curious what you and if you're a threat. Once they determine you are neither they usually move on. Startling a bear moves you high up on the threat level and is usually why people get attacked. Making noise (especially important in grizzly country) is a great way to alert bears that you're coming. Clapping, whistling or just talking with friends works fine. Bells have been proven not to be very effective.
Your food smells very good to bears. To avoid encounters for food, be sure to cook well away from where you sleep. Hang your food and food like substances (lip balm, toothpaste, etc). In grizzly country, have a separate change of clothes for cooking as for sleeping and hang the cooking clothes. If you are not around suitable trees to hang you can use bear cans. DO NOT bring food into your tent.
It is true that when you are being attacked by a bear you need to play dead. This proves you are not a threat. If you are continued to be bitten though, it means the bear is thinking you are food. That is when you fight your ass off.
For grizzlies, pepper spray is required gear to carry with you. It has been proven more effective then guns.
Prevention is the best medicine. Don't attract bears and know how to avoid them. Learn what bear signs look like (tracks, scat, fur, etc). I've hiked and lived in bear country for many years. I've seen black bears in my camp only a couple times. These techniques have worked for me and thankfully I've not ever been in danger. The odds are in your favor. Just be smart.