Answer:
The unions occur by the interactions of the valence electrons of each pair of atoms, which permit to reach the most stable configuration, that of a complete last shell, and they are, mainly, one of trhee types:
Explanation:
Two atoms will bond together depending on the interactions between their respective outermost electrons or valence electrons, i.e. the electrons that have the highest main energy level.
Metalic atoms of the groups 1 and 2 have 1 and 2 valence electrons respectively, so they can release 1 or 2 electrons, respetively, to reach the configuration of a noble gas (full valence shell).
Non metal atoms of groups 16, and 17, have 6, and 7 valence electrons respectively; so they can gain 2 or 1 electrons, respectively, to end with a full valence shell.
When a metal atom transfer one or two electrons to a nonmetal atom the former forms a positive ion (cation) and the latter forms a negative ion (anion). Then, these two ions are electrostatically attracted to each other forming a ionic bond.
Two non-metal atoms normally will share their valence electrons, instead of transfering them, forming covalent bonds.
Metal atoms have delocalized electrons which can be loosely attracted by the nuclei of other metal atoms forming what is usually called a "sea of electrons". This is the metallic bond.