# '!' Operator before an array

**URL:** <https://forum.freecodecamp.org/t/operator-before-an-array/499178>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [March 2, 2022, 9:18pm UTC](https://forum.freecodecamp.org/t/operator-before-an-array/499178 "2022-03-02T21:18:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![teller890](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@teller890](https://forum.freecodecamp.org/u/teller890)\
**Post date:** [March 2, 2022, 9:18pm UTC](https://forum.freecodecamp.org/t/operator-before-an-array/499178/1 "2022-03-02T21:18:46Z")

</div>

**Tell us what’s happening:**  
Describe your issue in detail here.

Hi all I was completing the Diff Two Arrays challenge and was looking at the sollutions. In solution two it used ‘!arr’ - My Question is what does the ‘!’ operator do in this situation. Thanks

```
  **Your browser information:**

```

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36`

**Challenge:** Diff Two Arrays

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![MatchaCrisp](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/matchacrisp/32/193162_2.png) [@MatchaCrisp](https://forum.freecodecamp.org/u/MatchaCrisp)\
**Post date:** [March 2, 2022, 10:25pm UTC](https://forum.freecodecamp.org/t/operator-before-an-array/499178/2 "2022-03-02T22:25:48Z")

</div>

the `!` operator is called the “logical NOT”, meaning whatever expression prefixed by `!` has its boolean value flipped to the opposite.

e.g. `!true` is false, `!false` is true.

I looked through the solution, and what actually was written was `!arr.includes()`, which means reverse the boolean return value of `arr.includes()`. Relevant MDN below:

> **[Array.prototype.includes() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)**
>
> The includes() method determines whether an array
> includes a certain value among its entries, returning true or
> false as appropriate.

---

<div class="post-metadata">

**Author:** ![Jagaya](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jagaya/32/202277_2.png) [@Jagaya](https://forum.freecodecamp.org/u/Jagaya)\
**Post date:** [March 2, 2022, 10:40pm UTC](https://forum.freecodecamp.org/t/operator-before-an-array/499178/3 "2022-03-02T22:40:33Z")

</div>

> [@teller890](#):
>
> In solution two it used ‘!arr’

You are reading that wrong.  
Generally the `!` inverts the value of a boolean. So `true` becomes `false` and `false` becomes `true`.  
So in the solution, it refers not to the arr itself, but there is some `arr.method()` which returns a boolean value and that one is getting negated → so read it as logical “not”.

Sidenote: “!arr” on an array would actually be “false” because boolean-checks consider an array as “truthy” and thus the negation is ALWAYS “false”. So it would be nonsens to just use it on an array itself.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [September 1, 2022, 10:41am UTC](https://forum.freecodecamp.org/t/operator-before-an-array/499178/4 "2022-09-01T10:41:30Z")

</div>

Closed on September 1, 2022, 10:41am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
