LearnFrenzy
Sign in Take a free test

Arrays · Predict the Output · Question 10

Searching for NaN Answer, explanation & discussion

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

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

main.js
const values = [1, NaN, 3];
console.log(values.includes(NaN), values.indexOf(NaN));
  • A true 1
  • B false -1
  • C true -1 Correct
  • D false 1
Correct Answer: Option C

includes uses SameValueZero (NaN equals NaN); indexOf uses === (NaN never equals anything).

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