# Symbol.primitiveSet

**URL:** <https://es.discourse.group/t/symbol-primitiveset/2127>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [August 31, 2024, 3:08pm UTC](https://es.discourse.group/t/symbol-primitiveset/2127 "2024-08-31T15:08:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ihasq](https://avatars.discourse-cdn.com/v4/letter/i/c4cdca/32.png) [@ihasq](https://es.discourse.group/u/ihasq)\
**Post date:** [August 31, 2024, 3:08pm UTC](https://es.discourse.group/t/symbol-primitiveset/2127/1 "2024-08-31T15:08:09Z")

</div>

Possible use case:

```javascript
let primitiveLike = {
     value: 0,
    [Symbol.toPrimitive](hint) {
        return hint == "string"
            ? String(this.value)
            : hint == "number"
                ? Number(this.value)
                : this.value
        ;
    },
    [Symbol.primitiveSet](value) {
        this.value = value;
        return true;
    }
}

primitiveLike++;

console.log(Number(primitiveLike)) // 1

```

This doesn't work when the object decleared as constant value.  
Do you think this will be needed?

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [August 31, 2024, 3:38pm UTC](https://es.discourse.group/t/symbol-primitiveset/2127/2 "2024-08-31T15:38:15Z")

</div>

Having a “primitiveLike” by itself seems like a massive problem - objects have a distinct identity, primitives do not, and while coercing between the two is possible, conflating them is highly undesirable.

---

<div class="post-metadata">

**Author:** ![ihasq](https://avatars.discourse-cdn.com/v4/letter/i/c4cdca/32.png) [@ihasq](https://es.discourse.group/u/ihasq)\
**Post date:** [August 31, 2024, 3:53pm UTC](https://es.discourse.group/t/symbol-primitiveset/2127/3 "2024-08-31T15:53:15Z")

</div>

Maybe the naming was inappropriate, but I think it's necessary to have the ability to determine the behavior when reassigned. I also don't think it's appropriate to hack the behavior of let, and I think it's better to have it work only with const.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [September 2, 2024, 9:35pm UTC](https://es.discourse.group/t/symbol-primitiveset/2127/4 "2024-09-02T21:35:34Z")

</div>

Assignments are to bindings - variables - not objects, and it just doesn't make any sense to me to have the way assignment works suddenly change and become fallible.
