All the elements gain or lose electrons to fulfill the octet in their outer shell so as to get maximum stability.
Step 2: Explanation :
An ionic is formed between two elements out of which one should be able to give away an electron from its outer shell and the other one should be able to accept an electron.
Or when a metal reacts with a non-metal, transfer of electrons takes place from metal atoms to the non-metal atoms, and an ionic bond is formed.
The metals are present on the left side of the periodic table- So they have the tendency to lose the electrons present in their outer shell
The chlorine has the capacity to accept one electron so that it can complete its octet.