LearnFrenzy
Sign in Take a free test

String Methods · Predict the Output · Question 12

startsWith and endsWith with positions Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

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

main.js
const file = "index.html";
console.log(file.endsWith("index", 5), file.startsWith("html", 6), file.endsWith(".htm"));
  • A true true false Correct
  • B false true false
  • C true false true
  • D false false false
Correct Answer: Option A

endsWith("index", 5) treats the string as "index"; startsWith("html", 6) starts checking at index 6. The full name ends in ".html", not ".htm".

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