<u>Answer:</u> In the reaction, magnesium atoms lose electrons.
<u>Explanation:</u>
An ionic compound is defined as the compound which is formed when electron gets transferred from one atom to another atom. These are usually formed when a metal reacts with a non-metal or a metal reacts with a polyatomic ion or a reaction between two polyatomic ions takes place.
Magnesium is 12th element of the periodic table having electronic configuration of 
This element will loose 2 electrons to form
ion
Chlorine is 17th element of the periodic table having electronic configuration of 
This element will gain 1 electron to form
ion
By criss-cross method, the oxidation state of the ions gets exchanged and they form the subscripts of the other ions. This results in the formation of a neutral compound.
The ionic compound formed is 
Hence, in the reaction, magnesium atoms lose electrons.