Leaderboard Archive
Javascript Apr 29, 2026

What does this print?

const arr = [1, 2, 3]
console.log(arr.indexOf(2))
console.log(arr.indexOf(5))
A 2 and -1
B 1 and -1
C 1 and 0
D 2 and 0
Explanation
indexOf returns the position (index) of the item you are looking for, starting from 0. So 2 is at position 1. If the item is not found, indexOf returns -1. Many developers use -1 as the "not found" signal to write conditions like: if (arr.indexOf(x) !== -1).
📝
Reviewed by CodeShot Editorial
Every challenge is code-reviewed by senior developers to ensure accuracy and real-world relevance. Learn more.

Ready for your shot?

Join thousands of developers solving one logic puzzle every morning.

Solve Today's Challenge →