To add to the above answer, the reason this compound is ionic is due to the transfer of the electrons which is due to the difference in the electronegativities of both elements.
Electronegativity is the attraction of one atom's nucleus (protons) for another atom's valence electrons in a bond. It is similar to a tug-of-war between two atoms and the valence electrons. The element with the strongest electronegativity value wins the tug-of-war. In this compound, sodium has an electronegativity value of 0.9 while chlorine has an electronegativity value of 3.0. This means that chlorine would attract the valence electron of sodium's because chlorine's nucleus attracts that electron more strongly than sodium does.
The electron transfers to chlorine which completes an octet (8 valence electrons) in chlorine and becomes the chloride ion with a -1 charge. Sodium has lost its only valence electron which leaves an octet for sodium as well and creates a +1 charge. Since opposite charges attract, the sodium ion and chloride ion attract and form a bond.
"Bond Polarity and Electronegativity," Michael Blaber Ph.D.