Javascript code validation recommendation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Haitashi
    New Member
    • Jun 2007
    • 96

    Javascript code validation recommendation

    I'm trying to see what, inside a script of 500 lines, is messed up. It was written by a previous developer so I was trying to see if there was any way to validate the syntax (to make sure he's not missing something silly like a semi-colon somewhere).

    Are there any software or web apps out there for this? After searching the web I found JSLint but it's too strict on the validation. For example, it says this is an error:
    Code:
    var credits = new Array();
    It tells me: "Use the array literal notation []."
    As I understand it, there is nothing wrong with declaring the array the aforementioned way. Using [] was the "old" way of doing it.

    Thanks!
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Use Mozilla Firefox and go to Tools >> Error Console

    Or download one of the add-ons for Mozilla.
    I use this one.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      yes ... or use the firebug extension ...

      but one more note according to the 'error' you posted:

      [CODE=javascript]var a = new Array();[/CODE]
      is syntactically correct of course but you should always prefer the literals. it is not the 'old' way ... it is just the best way for following reasons:

      1. in case you don't pass arguments to the constructor then you could even write:

      [CODE=javascript]var a = new Array;[/CODE]
      why? : there is no need for the js-interpreter to be forced to evaluate an empty list of arguments so we just could leave the parantheses out

      2. since using literals is much shorter and even less to evaluate for the interpreter (new Array => 2 keywords) and [] is just one instruction to be evaled ... it is just better to use the literals. you even wouldn't create a string with the constructor or a number ... or would you? ;)

      kind regards,
      gits

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        You can configure jslint to skip warnings that you don't care about...

        Comment

        • Haitashi
          New Member
          • Jun 2007
          • 96

          #5
          Great responses. Thanks guys!

          Ty for all that useful info Gits. I just getting in JS so all of that is valuable info.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            ... you know that you just have to post to the forum in case you have any questions :)

            kind regards

            Comment

            Working...