Magnesium chloride is an ionic compound. Ionic bonds are created between ions, which are positively and negatively charged atoms.
Ions are formed when atoms lose or gain electrons. Because electrons are negatively charged, an atom becomes negatively charged when it gains an electron and positively charged when it loses one. Once an atom donates an electron to another atom and the atoms become oppositely charged, they attract one another; this attraction forms a bond between the two atoms, though it is not quite as strong as a covalent bond. The overall charge of the compound is neutral, however, as the positively and negatively charged ions balance each other out.