Answer
Sodium chloride is a molecule containing one atom of sodium and one atom of chlorine. The chlorine atom attracts the electron of the sodium, which is very loosely bound. So the sodium atom loses one electron and becomes positively charged, and the chlorine atom gains one electron, becoming negatively charged. Then these oppositely charged atoms attract each other and form an ionic bond.
Work Step by Step
The sodium atom has only one electron in its outermost shell. This electron is very loosely bound to the atom, because after losing it, the remaining electrons form a complete octet, which is a very stable configuration. On the other hand, the chlorine atom has only one electron short of a complete octet, so it attracts that electron, because after gaining one electron, its octet becomes complete, which is a very stable configuration.