Question 9
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const invoiceNo = 42;
console.log("INV-" + invoiceNo.padStart(5, "0"));
- A It prints INV-00042
- B It prints INV-42
- C It prints INV-42000
- D TypeError: invoiceNo.padStart is not a function – numbers have no string methods; use String(invoiceNo).padStart(5, "0") Correct
Correct Answer: Option D
padStart belongs to String.prototype. Convert first: String(invoiceNo).padStart(5, "0") gives "00042".
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!