Question 4
Back to Exercise
JavaScript refuses to run the code below. Which statement correctly describes the problem?
console.log(5.toFixed(2));
- A SyntaxError: the dot after 5 is read as a decimal point – write (5).toFixed(2) or 5..toFixed(2) Correct
- B It prints 5.00
- C TypeError: 5 has no methods
- D It prints 5
Correct Answer: Option A
"5." is the start of a decimal number, so toFixed is unexpected. Parentheses, a space before the dot (5 .toFixed(2)) or a second dot fix it; a variable (n.toFixed(2)) has no such problem.
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!