Метод includes () проверяет, включает ли массив переданный элемент или нет. Если массив содержит этот элемент, он вернет true, иначе он вернет false.

Метод indexOf () проверяет, включает ли массив переданный элемент или нет. Но разница в том, что метод indexOf () возвращает позицию, он возвращает -1, если элемент не найден.

Проделаем определенную операцию с обоими методами.

Включает ()

const array = [5,11, 6, 2, 13, 7, 9, 25, 88]
if (array.includes(2)) {
    console.log(`array contain 2`) // array contain 2
}

indexOf ()

const array = [5,11, 6, 2, 13, 7, 9, 25, 88]
if (array.indexOf(2) >= -1) {
    console.log(`array contain 2`) // array contain 2
}

Давайте проверим NaN.

Включает ()

const array = [5,11, 6, 2, NaN, 7, 9, 25, 88]
if (array.includes(NaN)) {
    console.log(`array contain NaN`) // array contain NaN
}

indexOf ()

const array = [5,11, 6, 2, NaN, 7, 9, 25, 88]
if (array.indexOf(NaN) >= -1) {
    console.log(`array contain NaN`) // array contain NaN
}

Давайте проверим undefined.

Включает ()

const array = [5,11, 6, 2, undefined, 7, 9, 25, 88]
If (array.includes(undefined)) {
    console.log(“elements from array are undefined”) 
    // elements from array are undefined
}

indexOf ()

const array = [5,11, 6, 2, undefined, 7, 9, 25, 88]
if (!array.indexOf(undefined) == -1) {
    console.log(`elements from array are undefined`)
} else {
    console.log(`Can’t find undefined.`) // Can’t find undefined.
}

С отрицательным / положительным / нулевым.

const a = [-0].includes(0)
console.log(a) // true
const b = [-0].indexOf(0) >= -1
console.log(b) //true
const c = [-1].includes(1)
console.log(c) // false
const d = [-1].indexOf(1) >= -1
console.log(d) // true

Резюме:
Метод Includes () работает с NaN, undefined, Zero.

indexOf () работает с NaN, Zero, но не с undefined.

Если вы наберете compare -0 с +0, это правда.

console.log(-0 === +0) /// true