I have some definite opinions on this topic and some of them May or may not differ a bit from those already mentioned. I don't consider this a what if scenario, but an every day scenario.
Mas Ayoob's In the Gravest Extreme is a landmark work in gun ownership and useage. He was the first to address then legal implecations of using a gun. I made it required reading for people I knew that were thinking of buying a gun for defense. And that was back in the '80's. Read it!
Situational awareness will be an underlying foundation. No talking on the cell phone or texting. No fumbling for keys, which should already in hand or even too involved of a conversation if you're walking with someone Nothing to draw your attention away from your surroundings and who's in it.
Don't be afraid to verbally confront someone.
STOP! Hand(s) ✋ if necessary. This also creates a postive defensive posture, but that's another story. Their continued action may indicate their intent.
With a good light, you can obscure their vision and ask, "May I help you?" The light allows you to identify the subject and see what they may be carrying like a knife or gun of just books. If they continue forward into the light, that would be a big red flag for me.
On lights, contrary to the aforementioned suggestion, you do want a light that is operated by the tailcap and you will prefer it to have a momentary switch. A momentary switch is one that lights immediately when you press it. Not one that requires it to "click" on where you press and release for it to activate. This allows you to extinguish the light immediately and without noise going on or off. The end cap switch allows you to grip the light fully in the fist do it can be used as a striking weapon. Don't go for a light too large to grip this way. Also, avoid mega lumen super bright lights. They will screw up your night vision recovery. Optimally, it will be bright enough to overcome headlights that are pointed at you. Ever been in a dark parking lot when a car rolls up and you can't see who's in it?
There are now plenty of good powerful lights at decent prices. I would avoid the exotic battery types CR123, 18650, etc. if you are starting out. Too much upkeep. (I personally have them all, but I maintain a system to keep them running.) There are good AA lights out there and I prefer over AAA. My favorite EDC light uses a single AA. Standardize on AA's for as many things as you can and invest in Sanyo Eneloop AA NiMh rechargeables. These are by far the best rechargeable batteries out there for longevity. They keep working. (18650's in various brands are my other "standard".)
I can go on and on about lights. Have one. Have it in your hand. Learn to strike with one. Learn how to transition to a gun with one. (Gets back to the grip.) Learn when it needs to be off.
Back on situational awareness, if someone is getting your attention, be sure to "Check your 6" or look behind you. They often work in pairs. Assume he has a buddy and think of where he might be.
This isn't paranoia, it's just being prepared. It becomes second nature and done automatically. No fanfare or weird behavior.
Just my .02
I know I didn't cover everything.