So, as you know, strict JavaScript mode adds restrictions on the identifiers eval and arguments , effectively making them reserved words with two exceptions:
- they can still be used as expressions, i.e. where expression is expected (with a few exceptions)
- they can still be used as label names, and in the
break / continue statements, label references.
Now I understand the first bullet. If, for example, the identifier eval not resolved as an expression (but the true reserved words were not), we would not be able to call the eval function at all (since eval(str) is an expression). The same goes for arguments — we need to be able to use it as an expression in order to have access to its elements (for example, arguments[0] ).
This rule has three exceptions. eval / arguments may not appear (1) as left expressions in assignments (e.g., eval = true; ), (2) as operands ++ / -- (e.g., eval++ ), (3) as delete operands (e.g., delete eval ). These are the only exceptions, although they are valid in all other context expressions.
What I do not understand is the second bullet. Why can they be used as shortcut names? For example, this code is valid even in strict mode:
eval: for ( var i = 0; i < 10; i++ ) { arguments: for ( var j = 0; j < 10; j++ ) { if ( i < j ) continue eval; console.log( i - j ); } }
Note that continue eval; refers to the eval label and has nothing to do with the actual eval function.
Also note how true reserved words cannot be used as label names. In my opinion, the intent of strict mode was to make the names eval and arguments as reserved words as possible. Then why store them as valid label names?
source share