HCl is formed by hydrogen and chlorine. Hydrogen has one electron
in K shell and chlorine has two electrons ion K, 8 in L and 7 electrons in
M shell. By sharing one electron each from H and Cl, hydrogen completes its
duplet and chlorine its octet and gets a stable molecules.
These different methods of acquiring an octet (or duplet) of electrons in the outer most shell give rise to different types of chemical bonding. The losing or gaining of electrons leads to ionic bonding, while the sharing of electrons leaves to covalent bonding, of which there are several different types.