Magnesium has 2 valence electrons, and oxygen has 6 valence electrons, which type of bonding is likely to occur between a magnesium atom and an oxygen atom?
The reactivity of atoms is governed by their "desire" to obtain a stable electron configuration for their outermost energy shell.
On the other hand, oxygen,
When a magnesium atom reacts with an oxygen atom, magnesium gives up its two valence electrons and becomes a positively charged ion, i.e. a cation,
The cation and the anion will then be attracted to each other by way of the electrostatic force of attraction