That's called non-volatile memory. Do you know USB-sticks? That's non-volatile memory also. It keeps its data even when it's in your pocket without any battery.

And, but that's somewhat more technical, so is the BIOS in your laptop: it not only keeps it programs but also your settings even if you remove the battery.