Since gas and electric water heaters still sell more than all other water heater types in the marketplace, the question might come down to which of the two is better for you. Both have benefits, so you might have to make a few compromises.
What type do you already own?
If you're building a new home, your options are virtually limitless, but if you already have a water heating system, it might be wise to continue with the same fuel. The costs of adding a natural gas line to your home could be high. If your furnace is gas but the water heater is electric, you could potentially save money down the road by switching to all gas. Propane is also often less expensive than electricity, if you already have access to it.
The higher the energy factor of a water heater, the more efficient it is. Gas water heaters' energy factors range from .5 to .7, while electric models have factors between .75 and .95. So, electric heaters are more efficient, but if electricity is several times more expensive, gas heaters will still likely be cheaper to run.
Gas (usually) wins hands down in tankless heating
If you've decided to purchase a tankless water heater, keep in mind that gas-fueled units can usually produce more gallons per minute (gpm) than electric. If you often use more than one hot-water-demanding appliance at a time, it's an important consideration.
However, when comparing an electric tankless and a gas storage unit, it's electric that comes out on top. Some say the power needed just to keep water continuously hot in a gas-fueled tank (before any water is used) exceeds the total amount used with an electric tankless.
Storage water heaters - benefits for both
Electric units are cheaper to buy and easier to install. Plus, there is an assurance of safety - no chance of a fuel leak or an explosion.
The benefit of a gas unit all depends on how much gas costs where you live. In some areas, gas is several times cheaper than electricity. For instance, in California, natural gas can be one-third the cost of electricity when heating water.