Equality of object property names depends on code units
- 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", uΜ: "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. ;)
Related Topics
Related Articles
- How to create an API wrapper using a JavaScript proxy
- "fetch" supports a "keepAlive" option to make it outlive page navigations
- A clipboard magic trick - how to use different MIME types with the Clipboard API
- Keyboard button clicks with Space and Enter behave differently
- VS Code supports JSDoc-powered type checking