Chlorine has 7 valence electrons. In order to have a full outer shell, it needs to gain one electron. When it forms an ionic bond with sodium, it does just that. Sodium has 1 valence electron, which it donates to chlorine, giving chlorine a full outer shell of 8 electrons.