It's generally easier to move something than to make something. Putting that principle to use, HPWHs use electricity to move heat from one place to another instead of generating heat directly.
To understand the concept of heat pumps, imagine a refrigerator working in reverse. While a refrigerator removes heat from an enclosed box and expels that heat to the surrounding air, a HPWH takes the heat from surrounding air and transfers it to water in an enclosed tank.
A low-pressure liquid refrigerant is vaporized in the heat pump's evaporator and passed into the compressor. As the pressure of the refrigerant increases, so does its temperature. The heated refrigerant runs through a condenser coil within the storage tank, transferring heat to the water stored there. As the refrigerant delivers its heat to the water, it cools and condenses, and then passes through an expansion valve where the pressure is reduced and the cycle starts over.