The electronegativity of an element is a measure of the power of its atoms to attract electrons when forming chemical bonds.
The greater the power to attract electrons, the greater the electronegativity.
Let’s look at how this idea applies to chlorine and sodium chloride.
In the Cl2 molecule the two identical atoms have an equal ‘appetite’ for electrons: their electronegativities are equal, so the electron pair is shared equally between them.
But this clearly can’t be the case for sodium chloride.
Which atom is the more electronegative, sodium or chlorine?
As the chlorine atom is acquiring an electron to form an anion, logically you’d expect chlorine to be the more electronegative.
In fact in sodium chloride, the electron pair has been completely taken over by chlorine, which forms a chloride ion.