Question: Beyond the improved readability, is there any advantage to `includes` over `indexOf`? They seem identical to me.

What is the difference between this

```
var x = [1,2,3].indexOf(1) > -1; //true

```

And this? 

```
var y = [1,2,3].includes(1); //true

```

Answer: 
**tl;dr:** `NaN` is treated differently:

* `[NaN].indexOf(NaN) > -1` is `false`
* `[NaN].includes(NaN)` is `true`

---

From the [proposal](https://github.com/tc39/Array.prototype.includes/#motivation):

> 
> ### Motivation
> 
> 
> When using ECMAScript arrays, it is commonly desired to determine if the array includes an element. The prevailing pattern for this is
> 
> 
> 
> ```
> if (arr.indexOf(el) !== -1) {
>     ...
> }
> 
> ```
> 
> with various other possibilities, e.g. `arr.indexOf(el) >= 0`, or even `~arr.indexOf(el)`.
> 
> 
> These patterns exhibit two problems:
> 
> 
> * They fail to "say what you mean": instead of asking about whether the array includes an element, you ask what the index of the first occurrence of that element in the array is, and then compare it or bit-twiddle it, to determine the answer to your actual question.
> * They fail for `NaN`, as `indexOf` uses Strict Equality Comparison and thus `[NaN].indexOf(NaN) === -1`.
> 
> 
> ### Proposed Solution
> 
> 
> We propose the addition of an `Array.prototype.includes` method, such that the above patterns can be rewritten as
> 
> 
> 
> ```
> if (arr.includes(el)) {
>     ...
> }
> 
> ```
> 
> This has almost the same semantics as the above, except that it uses the SameValueZero comparison algorithm instead of Strict Equality Comparison, thus making `[NaN].includes(NaN)` true.
> 
> 
> Thus, this proposal solves both problems seen in existing code.
> 
> 
> We additionally add a `fromIndex` parameter, similar to `Array.prototype.indexOf` and `String.prototype.includes`, for consistency.
> 
> 
> 

---

Further information:

* [`SameValueZero` algorithm](http://www.ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* [`Strict Equality Comparison` algorithm](http://www.ecma-international.org/ecma-262/6.0/#sec-strict-equality-comparison)
The answers and examples were all great. However (at first glance), it made me misunderstood that `includes` will always return `true` when using `undefined`.

Hence I am including the example to elaborate **includes can be used to check for undefined and NaN values** wherelse **indexOf can't**

```js
//Array without undefined values and without NaN values. 
//includes will return false because there are no NaN and undefined values

const myarray = [1,2,3,4]

console.log(myarray.includes(undefined)) //returns false
console.log(myarray.includes(NaN)) //returns false

//Array with undefined values and Nan values.
//includes will find them and return true

const myarray2 = [1,NaN, ,4]

console.log(myarray2.includes(undefined)) //returns true
console.log(myarray2.includes(NaN)) //returns true

console.log(myarray2.indexOf(undefined) > -1) //returns false
console.log(myarray2.indexOf(NaN) > -1) //returns false
```

Summary

* `includes` **can** be used to check for undefined and NaN values in array
* `indexOf` **cannot** be used to check for undefined and NaN values in array