Equality of object property names depends on code units

1 min read

This post is part of my Today I learned series in which I share all my learnings regarding web development.

Today I was writing a quick blog post on hidden characters in object property names and while writing this I came across my learning of the day.

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.

This means that an object can have to properties that look the same but consist of different code units. So let's have a look at an example.

const unicodeObject = {
    ü: 'foo',
    u\u0308: 'bar'

// evaluates to:
// {ü: "foo", ü: "bar"}

The properties look the same but are actually not because they consist of different code units. If you're interested in more details on property names check out the blog post there is way more cool stuff in it. ;)

Load time