All elements achieve octet configuration by-
Gaining electrons
Losing electrons
Sharing electrons
All elements try to achieve octet configuration by following three ways:
1. Sharing of electrons
2. Losing electrons
3. Gaining electrons
Sharing of electrons forms a covalent bond. Ex. H2
Loosing and gaining of electrons forms an ionic bond (Ex. NaCl). Na lost an electron to form Na+ and Cl gained an electron to form Cl−