This works.
var a = 'ontouchstart' in window;
for (;;) {
console.log(a);
break;
}
This causes syntax error. Why?
for (var a = 'ontouchstart' in window;;) {
console.log(a);
break;
}
This works.
for (var a = ('ontouchstart' in window);;) {
console.log(a);
break;
}
To avoid confusion with for-in-loops. The syntax specification for for-loops is explicit:
This
NoInsuffix spreads through the whole syntactic grammar, and ends in the 11.8 Relational Operators (Syntax) section:However, I don’t understand myself why the
NoInvariants are used in the normal for-loop – they are reasonable in for-in-productions. I’d guess it’s to avoid confusion of the programmer and to simplify parsers.