Array Includes Method
Multiple Choice Beginner
Question
What does [1,2,3].includes(2) return?
Hint
includes checks for membership.
Explanation
[1,2,3].includes(2) returns true because 2 is in the array. includes() uses the SameValueZero algorithm (like === but treating NaN === NaN as true). It is simpler than indexOf() which returns the index or -1. For objects, includes checks reference equality, not deep equality.
Related Resources
Related Lessons
- Arrays
Learn JS arrays.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.