Why can’t I access a property of an integer with a single dot?

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 NumberLiterals here, just because there’s actually not very much demand for things like 3.foo.

Leave a Comment