Magnesium attains a stable octet by loss of two electrons while each chlorine atom attains a stable octet by gain of one electron each.
The octet rule states that atoms are stable when they have eight electrons around their outermost shell. The driving force behind chemical bonding is this tendency towards stability.
Chlorine has seven outer electrons and magnesium has two outer electrons. The magnesium atom could donate one electrons to each chlorine atom to form two chloride ions as shown. By so doing, all three atoms will have attained a stable octet.
Learn more: https://brainly.com/question/14283892