I suppose that just like guns, cars, computers or any other consumer product, they work a bit differently from one unit to the next.
As an example, the one safe I own with an electronic lock will beep and flash a small led light when you open it if the the battery is getting low. Once that happens it will continue to function at least a few more months even if I open it several times per day. The battery is accessible from the outside so if it dies completely you just replace the battery then you can open it. The code is stored on flash memory similar to a USB flash drive, so it requires no power to retain information. As a result, the access code is not lost or changed when the battery dies or is removed. My safe does not have an override key so the electronic lock is the only access. Plan B if the lock fails or if SHTF and I can't get a 9volt battery is a locksmith or a cutting torch.
Its probably not the most secure safe that money can buy, but it was reasonably priced and was an way to keep guns and important papers more secure than a sock drawer.