Just like a rubber band if one stretches it energy is stored in it. This stored energy can be released back one string is released similarly a battery works by storing chemical energy inside itself, and when you connect it to a device, it releases that energy as electricity through a chemical reaction.