Of course people are comparing one kind of car against another. But the question as worded is rather silly, because it is making an incorrect assumption.
What does the question mean by electric cars have no onboard energy source? The person asking the question must believe that gasoline burned in a gasoline engine is an energy source where electricity stored in a battery pack is not an energy source.
Therefore we have to ask: Is gasoline an energy source?
And after a little thought you have to agree, no, gasoline is not an energy source. The energy embodied in gasoline came from sunlight that hit this planet millions of years ago. That ancient sunlight caused plants and animals to grow. When those plants and animals died, their bodies were buried and eventually became gasoline after several million years.
Therefore the real energy source was sunlight striking the planet in ancient times.
Gasoline is simply a mechanism for carrying ancient sunlight into modern times.
Electric cars have a rechargeable battery pack in which to store energy. Gasoline and diesel cars have a fuel tank in which to store energy.
Both kinds of vehicle carry a limited amount of energy, and must be refueled from time to time. Neither kind of vehicle inherently has what can be called an energy source.