This is because chemical compounds are formed by the sharing or transfer of electrons between atoms.
* Ionic compounds are formed when one or more electrons are transferred from one atom to another, resulting in the formation of ions with opposite charges. These opposite charges attract each other and hold the compound together.
* Covalent compounds are formed when atoms share electrons. While the shared electrons may spend more time near one atom than the other, the overall sharing leads to a balance in charge distribution.
In both cases, the positive and negative charges within the compound must balance out to create a neutral overall charge.