LearnFrenzy
Sign in Take a free test

Operators · Predict the Output · Question 19

The in operator with an array Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 19 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
const arr = ["a", "b"];
console.log(0 in arr, "a" in arr, "length" in arr);
  • A false true false
  • B true true true
  • C true false true Correct
  • D false true true
Correct Answer: Option C

in checks keys, not values. Index 0 is a key of the array, "a" is a value, and length is an own property of every array. Use includes() to search values.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links