Assess the situation and try to understand the message the bear is conveying before you act. Fleeing may trigger a chase response. Standing on its hind legs is seldom a precursor to an attack. The bear is trying to get a better look, or smell, at something it is uncertain of. Do not make direct eye contact with the bear because the gaze may be interpreted to be a challenge.
Excessive salivation is a universal sign of nervousness.
A stalking bear usually walks deliberately, stares, and looks ominous no matter how innocent its intentions. If the bear starts to stalk, you may try dropping your pack and food stuff, then slowly back away in a lateral direction keeping an eye on the bear. If the bear continues to follow, stop, stand your ground. Shout, wave your arms. Raise your jacket or pack to look bigger.