# Non-null assertion operator (aka Swift's force unwrap)

**URL:** <https://es.discourse.group/t/non-null-assertion-operator-aka-swifts-force-unwrap/1085>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [November 15, 2021, 11:18am UTC](https://es.discourse.group/t/non-null-assertion-operator-aka-swifts-force-unwrap/1085 "2021-11-15T11:18:09Z")\
**Posts on this page:** 1\
**Showing post:** 11

<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:** [November 16, 2021, 10:18pm UTC](https://es.discourse.group/t/non-null-assertion-operator-aka-swifts-force-unwrap/1085/11 "2021-11-16T22:18:40Z")

</div>

For example, I would love to see something like [this assertion idea](https://es.discourse.group/t/error-assert/356) go through. It would allow you to do something like `TypeError.assert(someCondition)`. Many languages have some sort of assert function or statement. It would be nice if JavaScript does as well.

I guess someone could utilize the fact that `null!` will always throw an assertion error, and with a bit of hacking, emulate assertions as follows:

```javascript
function operateOnArray(array) {
  Array.isArray(array) || null!
  ...
}

```

But, it would be preferable to just provide a native assert function.

```javascript
function operateOnArray(array) {
  TypeError.assert(Array.isArray(array))
  ...
}

```

---

_[View the full topic](https://es.discourse.group/t/non-null-assertion-operator-aka-swifts-force-unwrap/1085)._
