Electronic configuration of Mg (Z = 12) is
K L M
Mg (Z = 12): 2 8 2
Magnesium is a metal. Its compound with non-metallic oxygen is an electrovalent compound. Therefore, in the formation of magnesium oxide, magnesium atom loses two electrons from its valence shell to attain the stable octet structure of nearest noble gas (Ne).