LearnFrenzy
Sign in Take a free test

String Methods · Predict the Output · Question 5

Length after trimming Answer, explanation & discussion

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

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

main.js
const s = " \t hi there \n";
console.log(s.trim().length, s.trimStart().length, s.length);
  • A 8 8 13
  • B 8 10 13 Correct
  • C 7 10 13
  • D 8 11 12
Correct Answer: Option B

"hi there" has 8 characters. trimStart removes the 3 leading characters (space, tab, space), leaving 10. The full string has 13.

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