Equality of object property names depends on code units
Written by Stefan Judis
- Published at
- Updated at
- Reading time
- 1min
This post is part of my Today I learned series in which I share all my web development learnings.
Today I was writing
on hidden characters in object property names, and while writing it I came across today's learning.The ECMAScript spec describes equality for property names as follows:
Two IdentifierName that are canonically equivalent according to the Unicode standard are not equal unless they are represented by the exact same sequence of code units.
An object can have two properties that look the same but consist of different code units. Let's look at an example.
const unicodeObject = {
ü: 'foo',
u\u0308: 'bar'
}
// evaluates to:
// {ü: "foo", ü: "bar"}
The properties look the same but are not because they consist of different code units. If you're interested in more details on property names, check out my blog post "Hidden messages in JavaScript property names", there is way more cool (and scary) stuff in it. ;)
If you enjoyed this article...
Join 5.4k readers and learn something new every week with Web Weekly.
Reply to this post and share your thoughts via good old email.