The bonding is covalent in homonuclear diatomic molecules. Each atom in the molecule has the same electronegativity, which means electrons are shared equally between the two. The electronegativity of the atoms in heteronuclear diatomic molecules varies, and these molecules have polar covalent bonds. A dipole is formed when a molecule interacts with another molecule. (i think it's covalent bonding but i might be wrong)
A covalent bond! A hydrogen molecule forms from two hydrogen atoms, each with one electron in a 1 s orbital. The two hydrogen atoms are attracted to the same pair of electrons in the covalent bond. A covalent bond is the force of attraction that holds together two atoms that share a pair of electrons. The shared electrons are attracted to the nuclei of both atoms. Covalent bonds form only between atoms of nonmetals. The two atoms may be the same or different elements. If the bonds form between atoms of different elements, a covalent compound forms.
Whether you get the metal or hydrogen during electrolysis depends on the position of the metal in the reactivity series: the metal will be produced if it is less reactive than hydrogen. hydrogen will be produced if the metal is more reactive than hydrogen.