When magnesium forms a compound with fluorine, it undergoes an ionic chemical reaction. Magnesium is a metal and fluorine is a non-metal. When these two elements react, magnesium loses two electrons to fluorine, resulting in the formation of positively charged magnesium ions (Mg²⁺) and negatively charged fluoride ions (F⁻). These ions then combine to form an ionic compound called magnesium fluoride (MgF₂).
The chemical reaction between magnesium and fluorine can be represented as follows:
```
Mg(s) + 2F₂(g) → MgF₂(s)
```
In this reaction, solid magnesium (Mg) reacts with gaseous fluorine (F₂) to produce solid magnesium fluoride (MgF₂). The reaction is highly exothermic, meaning that it releases a large amount of heat.