Top 7 most common mistakes with Javascript syntax

Ok, my basis for saying “most common” is not at all scientific, just a gut sense of how many times I’ve seen 15 mins or more spent trying to find a bug that ended up being just a syntax error in one’s script. Tools like JSLint and Firebug are really helpful in general, but not with these issues. (I’ve heard Aptana should be, but I couldn’t get it to work and it kept crashing on me.)

  1. Spurious comma after the last entry in a JSON object string

    {name:’Fred’,visits:3,}

  2. Use of = instead of : in a JSON object string

    {name=‘Fred’}

  3. Misspelled function and object names

    encodeURICompoent

    onReadyStateChange instead of onreadystatechange

  4. Spurious parenthesis after a function call

    confirm(‘Proceed?’));

  5. Using parenthesis instead of braces for access within arrays and objects

    htsVisits(‘Fred’)

  6. Spurious : between keyword case and a switch value

    case: 1:

  7. Expecting “False” or new Boolean(“False”) to evaluate as true
Print Friendly, PDF & Email