So this is a question that can be a little better understood if we think of electronegativity. So if you can imagine a periodic table (Look at the graph trends).
Electron pairs shared between atoms of equal or very similar electronegativity constitute a nonpolar covalent bond (Usually shared between 2 non-metals atoms ie. H–H or C–H), while electrons shared between atoms of unequal electronegativity constitute a polar covalent bond (like the Alkaline Earth Metal group & Halogen group, which is a hybrid of metal & non-metal atoms ie. BeO).
Essentially an Ionic bond is under the umbrella of polar bonds where two molecules, an atom with a really low electronegativity (Ie. an atom from a Alkali Metal group) shares a bond with an atom with a really high electronegativity (Ie. an atom from the Halogen group). The electrons are more willing to go from a low electronegativity to one with a really high electronegativity, and to make it simple, it's much easier to take away 1 electron than 7, right? So it leaves the Alkali metal, which had 1 valence electron [in GROUP 1 of the periodic table (ignoring the transitional metals)], leaves the atom to have a +1 charge, and the halogen atom which had 7 valence electrons (in GROUP 7 of the periodic table), leaves it with 8 valence electrons so now it's a negatively charged atom ( Ie. Na+ & Cl-). A nice tip I learned was that every atom wants to be like a noble gas which has 8 valence electrons, in GROUP 8 of the periodic table, therefore the Cl- has 8 valence so now it's "stable", and taking an electron away from Na, leaves it in Na+ which is back to a somewhat "stable" electron shell configuration.
I hope this helps!