From the formula of the compound it may not be possible to know that the bond present in a compound is ionic or covalent.
H2 O, Cl2 , Na Cl , K F, K Cl , B F3, H Cl , Na OH, O2, O3, Fe O2, Si O2, CO2,
From the nature of the elements (or functional groups or radicals) inside the compound, we may be able identify the nature of the bonds.
Where metals are present, usually they are ionic bonds. Where there are Cl, F or OH elements present they are likely to be ionic bonds. We come to know from this nature only after studying a lot of the compounds and properties of elements and their relative electronegativity.