const arr = ['a', 'b', 'c', 'd', 'e'];
var x = "b" || "d" || "g" || "h" || "z";
const the_number_of_x = arr.filter(i => i === x).length;
if (the_number_of_x === 2) {
console.log("success!")
} else {
console.log("fail!")
}
x
라는 변수에 "b"
와 "d"
가 있고 arr
에도 'b'
, 'd'
총 2개가 있으니까 the_number_of_x
는 2
가 되는 거 아닌가요? 그런데 어째서 "success!"
가 아닌 "fail!"
이 나오는지 모르겠습니다.
알려주시면 감사하겠습니다.