Well, there are other cases where the context of where symbols appear affects how they behave, for example, statement Block's vs Object Literals:
{} // empty block
var o = {}; // empty object
({}); // empty object
0,{} // empty object
{ foo: 'bar'} // block, `foo` label, 'bar' ExpressionStatement
var o = { foo: 'bar'}; // object literal, declaring a `foo` property
// whose value is 'bar'
They look exactly the same, but blocks are evaluates in "statement context", object literals are evaluated in expression context.
Also, Function Declarations vs. Function Statements, e.g.:
function foo() {}.length; // SyntaxError, `foo` is a function declaration
0,function foo() {}.length; // 0, `foo` is a function expression
(function foo {}).length; // 0
The example you post, relates to the way the grammar of Numeric literals are defined, the decimal part after the dot is actually optional, for example:
var n = 0.;
Is a valid Numeric literal, that's why, accessing 0.toString
gives you a SyntaxError
, the interpreter would expect the decimal part, instead the s
character.
See also: