I have done a flame test with $\ce{NaCl}$ and got the yellow characteristic flame of sodium. I am trying to understand exactly how this yellow color is being produced and when I searched for it, I got conflicting answers.
I understand that it is being produced by excitted electrons that fall back and produce photons. I also understand that different elements have different energy levels for their electrons so when the electrons fall back, they will produce a different wavelength of photon and therefore a different color.
What I was trying to find out is whether the sodium that gets excited is still bound to the chlorine or if it is dissociated, becoming a free ion and then excited.
Most sources said the sodium ion is dissociated and then excited, but some sources argued the yellow flame is apparently produced by electrons getting excited from the 3s orbital to 3p and the sodium ion doesn't have the electron in the 3s orbital which is being excited, therefore it is actually a neutral sodium atom which is being excited. Would a neutral sodium atom, a sodium ion and a sodium ion bound to chlorine produce different colors when excited? And if the sodium ion is dissociated and then excited, then why does the anion still sometimes affect the color of the flame?