admin管理员组

文章数量:1289702

I receive this error,

 Expected an identifier and instead saw ')'.

in this lines of code. Any how to fix it?

   for (; index < nPageFullItemCnt; index++) {
        strIndex = "0" + index;
        keyIndex = "popup_item_" + strIndex.substr(strIndex.length - 2, 2);
        keyItem = document.getElementById(keyIndex);

        setPopupKeyText(keyIndex, " ");

        keyItem.className = "popupLangItemNone";
        keyItem.langId = "";
    }

I receive this error,

 Expected an identifier and instead saw ')'.

in this lines of code. Any how to fix it?

   for (; index < nPageFullItemCnt; index++) {
        strIndex = "0" + index;
        keyIndex = "popup_item_" + strIndex.substr(strIndex.length - 2, 2);
        keyItem = document.getElementById(keyIndex);

        setPopupKeyText(keyIndex, " ");

        keyItem.className = "popupLangItemNone";
        keyItem.langId = "";
    }
Share Improve this question edited Dec 20, 2012 at 12:49 Muthu Kumaran 17.9k5 gold badges50 silver badges72 bronze badges asked Dec 20, 2012 at 12:40 GibboKGibboK 74k147 gold badges451 silver badges674 bronze badges 3
  • What line number does it say, and what are the previous lines of your code? – AlanFoster Commented Dec 20, 2012 at 12:42
  • The error isn't happening within this code block. You need to share more code. – Bartek Commented Dec 20, 2012 at 12:43
  • 3 You have to know that JSLint is a very strict code quality tool that makes errors of what isn't really a big deal. Try using JSHint instead, it's more merciful. – Joseph Commented Dec 20, 2012 at 12:44
Add a ment  | 

2 Answers 2

Reset to default 2

You're not passing in the first parameter to the for() loop:

for (index = 0; index < nPageFullItemCnt; index++) 
{
    /* .. */
}

This bit:

for (; index

Is causing that error. The code should validate if you do this:

for (0; index

(As I assume you're not passing the first parameter, on purpose)

However, I'd suggest using a while loop, instead of a for, if you're not going to make use of the [initialization]; [condition]; [final-expression] properties in a for loop.

while(index < nPageFullItemCnt){
    // Do stuff;
    index++;
}

Technically, the 3 parameters are all optional, but some code validators can throw a error if they're missing.

本文标签: javascriptExpected an identifier and instead saw 39)39Stack Overflow