var b = 67.toFixed(2);
Simply generates a parsing error as the parser can't deduce that you meant it to be a number literal followed by a property accessor (Notice that the error is on the first line, not on the console.log(b)
)
The reason this works for 67.678.toFixed(2)
is that there's no other option. The parser can deduce without ambiguity that the number literal ended at the "8" digit and can continue parsing the next dot as a property accessor (which causes boxing into a Number
object first BTW).
A solution is obviously simple:
(67).toFixed(2);