mjs
mjs copied to clipboard
for loop is failing if any of the statements are omitted
The for loop parsing fails if any of the statements is missing. Each of these fail to parse:
let i = 0;
for (; i < 1; i++) {
// Do something
}
for (i = 0; ; i++) {
if (i == 1)
break;
}
for (i = 0; i < 1; ) {
i++
}
The JavaScript allows any of those to be omitted. While the 2nd and 3rd statement is rarely omitted, it is not that rare the 1st statement is omitted. The workaround is:
let i = 0;
for (i = i; i < 1; i++) {
// Do something
}