For this reason, we’ll use the more simple Bohr model to visualize the chemical compounds for salt and oxygen. In the salt compound, you will see that the chlorine atom is not very kind as it yanks away the one electron in the outermost (valence) shell in the sodium atom. So, there is a "hostile" transfer of an electron from the sodium to the chlorine atom.
In oxygen, one oxygen atom actually shares one electron from its valence shell electrons with the other oxygen atom, and vice versa. Now, why does a rude electron transfer occur in one scenario, while in the other, the atoms nicely share the electrons? The answer lies in two very important points: the importance of valence shells, and each atom’s number of protons and electrons.