Question 4
Back to Exercise
What does the following JavaScript code print (console output, as in Node.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!