I discovered this problem in TSR's post.
what is at first glance an equality is distorted by the fact that there are different types of spaces in HTML (and in editing) like non-breaking spaces, half-quadratin spaces, etc.
Which finally introduces a kind of logical trap for a simple equality test.
Because the equality test [for a computer] is limited to checking the encodings of the sequence of characters, whereas for a human being this difference in the encoding of spaces is irrelevant.
It is not a question of mathematics but of common language understanding.
I solved it this way, but not being too sure of my own, I also wonder if there could not be better to do, or if there is not already a native function in JS for that (researched but not found) and my mastery of regular expressions is far from perfect
const isTextEqual=(a,b)=>(a.replaceAll(/\s/g,' ')===b.replaceAll(/\s/g,' '))
var s1 = "USD 1,234.12"
var s1b = "USD 1,234.12"
var s2 = "USD 1,234.12"
console.log('s1 == s2 ->', s1 == s2) // is false because :
console.log(s1.codePointAt(3), s2.codePointAt(3)); // 32 , 160 is non breaking space
console.log('isTextEqual(s1,s2)->', isTextEqual(s1,s2) ) // true (as expected)
console.log('isTextEqual(s1b,s2)->', isTextEqual(s1b,s2) ) // false (as expected ?)
do you have a better way to encode this type of equality on a text, which allows to ignore the encoding of the space characters?