Reputation: 5780
(What kind of sorcery is this?)
I have two characters which looks the same, but when doing a comparison they are different:
console.log("i" === "i︆") // false
Then I compared their code which tell me it's the same, which is even stranger:
console.log("i".charCodeAt(0), "i︆".charCodeAt(0)) // 105 105
But finally I found the problem, the length of both characters is not the same:
console.log("i".length, "i︆".length) // 1 2
I'm wondering:
Upvotes: 1
Views: 322
Reputation: 1012
The second character has an invisible character with code 65030 which belongs to "VARIATION SELECTOR" block of the Unicode standard. When I copied your example, I got the same but when you type it, it will give TRUE. Result with the copy paste:
console.log("i".charCodeAt(0),"i".charCodeAt(1),"i︆".charCodeAt(0),"i︆".charCodeAt(1),"i︆".charCodeAt(2))
105 NaN 105 65030 NaN
Upvotes: 1
Reputation: 499
The second one has an invisble character (65030) at position 1.
console.log("i︆".charCodeAt(0), "i︆".charCodeAt(1))
Which means they're not 'strictly' equal.
Upvotes: 2