I have two identical strings in javascript with some spaces. When I printed the ascii values by using str.charCodeAt(n)
it is showing the values as 32 and 160. I googled the values and it is showing me as breaking and non breaking spaces. So can anybody explain what is this behaviour.
The difference between a normal (breaking) space and a non-breaking space is that text display and typesetting software should not insert an automatic line break in place of a non-breaking space. (It is as if the non-breaking space joins the words before and after it into an unsplittable word.) By contrast, a regular space is treated as a possible place to break a line.
Having said that, the code 160
is actually outside of the range of regular (7-bit) ASCII. The interpretation of 160
as a non-breaking space (or NBSP
) character comes from the Latin1 (ISO8859-1) character set. (In Extended ASCII, the code for the NBSP
character is 255
!)
References: