LearnFrenzy
Sign in Take a free test

String Methods · Predict the Output · Question 4

padStart and padEnd edge cases Answer, explanation & discussion

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

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

main.js
console.log("5".padStart(3, "0"), "12345".padStart(3, "0"), "7".padEnd(4, "ab"), "x".padStart(3));
  • A 005 345 7ab x
  • B 005 12345 7aba x Correct
  • C 005 12345 7abab x
  • D 500 12345 7aba x
Correct Answer: Option B

Padding never shortens a string. The filler is repeated and cut to fit ("aba"), and the default filler is a space, so "x".padStart(3) is two spaces then x.

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