Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Javascript code validation recommendation

Question posted by: Haitashi (Member) on May 15th, 2008 03:04 PM
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: ( text )
  1. 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!
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
hsriat's Avatar
hsriat
Expert
1,447 Posts
May 15th, 2008
03:29 PM
#2

Re: Javascript code validation recommendation
Use Mozilla Firefox and go to Tools >> Error Console

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

Reply
gits's Avatar
gits
Moderator
3,047 Posts
May 15th, 2008
04:08 PM
#3

Re: Javascript code validation recommendation
yes ... or use the firebug extension ...

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

Code: ( text )
  1. var a = new Array();

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: ( text )
  1. var a = new Array;

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

Reply
mrhoo's Avatar
mrhoo
Needs Regular Fix
399 Posts
May 15th, 2008
04:10 PM
#4

Re: Javascript code validation recommendation
You can configure jslint to skip warnings that you don't care about...

Reply
Haitashi's Avatar
Haitashi
Member
74 Posts
May 22nd, 2008
06:10 PM
#5

Re: Javascript code validation recommendation
Great responses. Thanks guys!

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

Reply
gits's Avatar
gits
Moderator
3,047 Posts
May 23rd, 2008
06:32 PM
#6

Re: Javascript code validation recommendation
... you know that you just have to post to the forum in case you any questions :)

kind regards

Reply
Reply
Not the answer you were looking for? Post your question . . .
178,103 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Javascript / DHTML / Ajax Forum Contributors