Hello Margaret,
In simple terms NaCl is used to harden the soap bar.
In more complicated terms, the sodium ion (Na+) from the NaCl which is highly soluble in water (which is the main constituent of the liquid phase of the soap) will enter in a competition with the other salts (mainly fatty acid salts) present in this phase and cause the least soluble one to precipitate and transfer to the solid phase (usually the aim is to precipitate the sodium laurate). This will harden the soap and will help improve the quality of the foam. Sodium Lactate, glycerin and some other water soluble additives work in the same way to harden the soap. (you should note that the hardening is not linear, and there is always a sweet spot that the formulator should find where you have the best foam, the best hardness, and of course the ideal longevity)
The stearic acid (or sodium stearate) is highly insoluble in water so it will be in the solid phase, so it will harden the soap and increase its longevity and help stabilise the foam.
There are several mechanisms to harden the soap, and usually all of them are used to a certain extent.