Electric water heaters can operate more efficiently because they do not lose heat through venting. And have instant heat when turning on. Electric water heaters also can fit in small/tight spaces. But electric water heaters won’t work if there is power loss and no backup power.
In a gas vs. electric water heater operating cost analysis, gas is usually cheaper. Natural gas is typically less expensive than electricity, and assumes that you already have access to natural gas in your home.