This is not true for mobile phones - my understanding is that they run off the battery regardless of whether they’re plugged into a charger or not.
The reason for this is that the battery is capable of delivered much greater transient current than the charger is, and there are several devices in a phone (the radio transmitter for a start) that demand high transient currents from their power source. So the phone is wired to charge the battery from the charger & power the phone from the battery - it cannot run itself from the charger. I don’t know whether the same is true for modern laptops.