# Deprecating the Boolean object

**URL:** <https://es.discourse.group/t/deprecating-the-boolean-object/1820>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [October 11, 2023, 8:13am UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820 "2023-10-11T08:13:36Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![donno2048](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/donno2048/32/1881_2.png) [@donno2048](https://es.discourse.group/u/donno2048)\
**Post date:** [October 11, 2023, 8:13am UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/1 "2023-10-11T08:13:36Z")

</div>

The problem is that `Boolean` is (afaik) the only type where `Type(new Type(x)) !== Type(x)`.

For example `String(new String(10)) === '10'` but `Boolean(new Boolean(false)) === true`.

It's absurd to have to access the value of the object in its own "type cast" or in an `if` statement for example.

I understand the reason this happens is that evaluating the "truthiness" of an object will yield `true` but this should be a special case, how come `document.all` gets to be a falsy "object" but a Boolean doesn't?

Also, there is no need for a Boolean object wrapper at all,

```js
Boolean(x) === !!x
new Boolean(x) ≈≈≈ { valueOf = () => !!x }

```

If for some reason someone needs a Boolean wrapper or to explicitly convert to boolean it's really simple to implement.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [October 11, 2023, 9:17am UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/2 "2023-10-11T09:17:23Z")

</div>

> [@donno2048](#):
>
> how come `document.all` gets to be a falsy "object" but a Boolean doesn't?

`document.all` was required because too many websites were using a bad pattern and they couldn't all be updated. For non-web hosts like Node, Deno, Bun, XS, they don't have `document.all` so they have the untainted model where "every object is truthy, no exceptions".

---

<div class="post-metadata">

**Author:** ![donno2048](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/donno2048/32/1881_2.png) [@donno2048](https://es.discourse.group/u/donno2048)\
**Post date:** [October 11, 2023, 10:01am UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/3 "2023-10-11T10:01:06Z")

</div>

OK, but it still doesn't justify **having** a Boolean object, it can just make things more complicated and maybe even confuse new developers...

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [October 11, 2023, 10:54am UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/4 "2023-10-11T10:54:15Z")

</div>

I agree, `Boolean` objects should be avoided. It is unlikely that `new Boolean` can be removed from the language now as that would be a breaking change. Linting rules and teaching materials should discourage its use in new code.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [October 13, 2023, 8:45pm UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/5 "2023-10-13T20:45:33Z")

</div>

Here's the long and short of it: `ToBoolean` does not depend on `Symbol.toPrimitive`, `valueOf`, or `toString`, largely for performance reasons.

All other primitives do depend on that, hence the difference.

---

<div class="post-metadata">

**Author:** ![donno2048](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/donno2048/32/1881_2.png) [@donno2048](https://es.discourse.group/u/donno2048)\
**Post date:** [October 20, 2023, 4:18pm UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/6 "2023-10-20T16:18:49Z")

</div>

`Boolean` is useless without `valueOf` as it's always `true` so it's really unnecessary to have it...

---

<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:** [October 20, 2023, 10:04pm UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/7 "2023-10-20T22:04:20Z")

</div>

None the less, it exists and must forever exist for backwards compatibility.

---

<div class="post-metadata">

**Author:** ![donno2048](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/donno2048/32/1881_2.png) [@donno2048](https://es.discourse.group/u/donno2048)\
**Post date:** [October 21, 2023, 8:03am UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/8 "2023-10-21T08:03:56Z")

</div>

Yeah, I'm not suggesting removing it completely only deprecating it

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [October 21, 2023, 2:04pm UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/9 "2023-10-21T14:04:34Z")

</div>

Define "deprecated"? If by that term you simply mean "discourage it's use", I think that's already being done?

---

<div class="post-metadata">

**Author:** ![donno2048](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/donno2048/32/1881_2.png) [@donno2048](https://es.discourse.group/u/donno2048)\
**Post date:** [October 21, 2023, 5:42pm UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/10 "2023-10-21T17:42:41Z")

</div>

Well, I figured Mozilla's mdn is the "official javascript documentation" and there the Boolean object isn't marked as deprecated.

---

<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:** [October 21, 2023, 5:56pm UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/11 "2023-10-21T17:56:33Z")

</div>

Because it’s not harmful to use it, so it shouldn’t be.

Boolean() is good and fine, it’s new Boolean() that should be avoided.

---

<div class="post-metadata">

**Author:** ![Josh-Cena](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/josh-cena/32/1408_2.png) [@Josh-Cena](https://es.discourse.group/u/Josh-Cena)\
**Post date:** [October 21, 2023, 6:18pm UTC](https://es.discourse.group/t/deprecating-the-boolean-object/1820/12 "2023-10-21T18:18:02Z")

</div>

@donno2048 MDN is not "official" as in, it's not "blessed by TC39". Our (MDN's) deprecation status faithfully reflects the spec and we don't make normative statements like deprecation ourselves. It would be TC39's job to mark `Boolean` objects as "deprecated", which I don't think they would do (the spec doesn't deprecate things just because it's hard to use or contains footguns; only dangerous or things never intended to exist can be). OTOH, the constructor page: [Boolean() constructor - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/Boolean) already has a mention that " You should rarely find yourself using `Boolean` as a constructor." which to me is a sufficient callout to developers. I do have plans, though, to update all primitive wrapper objects' landing pages so they start with a note like "you should almost never work with the wrapper objects".
