If I try to write
3.toFixed(5)
there is a syntax error. Using double dots, putting in a space, putting the three in parentheses or using br
This is an ambiguity in the Javascript grammar. When the parser has got some digits and then encounters a dot, it has a choice between "NumberLiteral" (like 3.5) or "MemberExpression" (like 3.foo). I guess this ambiguity cannot be resolved by lookahead because of scientific notation - should 3.e2
be interpreted as 300
or a property e2 of 3
? Therefore they voluntary decided to prefer NumberLiteral
s here, just because there's actually not very much demand for things like 3.foo
.