LearnFrenzy
Sign in Take a free test

String Methods · Predict the Output · Question 13

indexOf and case Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

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

main.js
console.log("Banana".indexOf("b"), "Banana".toLowerCase().indexOf("b"), "Banana".lastIndexOf("an"));
  • A 0 0 3
  • B -1 0 1
  • C -1 0 3 Correct
  • D 0 -1 4
Correct Answer: Option C

indexOf is case-sensitive, so lower-case "b" is not found in "Banana". The last "an" starts at index 3.

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