In a 'situation' the first choice is often to drive home, failing that to ride ( L, Bus, subway) and then to walk.
These all require different mindsets, planning, equipment and time.
There are some things they have in common though, which you can prepare yourself for.
Your need to know how to get where you are going is one of those things. You can prepare yourself for that in a few ways.
You should have a map. It does not need to be the most expensive, even a cheap street map can help a lot.
Get familiar with landmarks in your city, you should be able to orient yourself by looking at the city skyline. It might not be exact but it certainly does not hurt.
(edit: magnetic compasses are shockingly inaccurate in cities, too much metal and electricity around them)
It would be good to be familiar with your city's grid system. Knowing which side of the streets are odd numbers and even, which direction the numbers get bigger or smaller in Here the numbers get bigger as you go north and go west, the last place started from the center of town and the numbers grew as you went farther away from the town center. Whether the street names are alphabetical order or not you should know too. (again, for orienting yourself without a compass)
These are all things that can help you not get lost.
Of course you should walk at least some of your route once if you can. You should also explore alternate routes.
The shortest way home on foot is likely not the same as the fastest way to drive home, and it is likely to change in an emergency.