Ease your JavaScript testing and debugging load

Daily Newsletters

Sign up to ZDNet UK's daily newsletter.

Topics

JavaScript, debug

COMMENT

Web development platforms like JSP, ASP.NET, ColdFusion, and so forth offer plenty of powerful development options on the server side. However, they do not negate the role of client-side Web development with JavaScript.

JavaScript provides both logic and user interface features, while offloading processing from the server. While it has been with us for many years, development tools are still a bit awkward. Let's take a closer look at the development and debugging options for JavaScript.

Development tools
If you are accustomed to working with development IDEs like Visual Studio or NetBeans, then you are familiar with the various debugging options, which include stepping through code, setting breakpoints, and watching variables. These are invaluable tools when monitoring code execution or tracking down a bug. Unfortunately, these tools are not as prevalent for the JavaScript developer.

Debugging
A critical step in application development is tracking down bugs in a script or code. This involves isolating code chunks and analysing them line by line. When working with JavaScript, you can hearken back to methods used before the advancement of development tools.

In this scenario, the most often used JavaScript function is the alert message box. You can use it to inspect values stored in variables/objects and combine with a loop to view the contents of an object.

As an example, the HTML in Listing A is not executing as planned. Basically, it verifies values that are entered in two text fields before the form is actually submitted.

The form is always submitted regardless of values entered, so we can use alert statements to inspect the contents of values during script execution. The script in Listing B uses alert statements to monitor variable values.

If you execute the script, it is clear the if statements always evaluate to true. Upon closer inspection, you will notice the assignment operation is being used (=) as opposed to equality (==). By making these two changes, the script will execute as expected.

This error is common, especially when developers are moving back-and-forth between languages like VB.NET and others that have different syntax. Here's a quick look at more common errors:

 

  • JavaScript is case-sensitive, so variable names, JavaScript statements, and such must utilise proper formatting/case. Use a consistent naming convention for your objects, variables, and function names.
  • The use of commas throughout the code. With the exception of the for statement, JavaScript uses the comma as the separator character for arguments.
  • JavaScript uses curly braces to define a block of statements.
  • Strings must be enclosed in quotes (single or double).

 

Debugging with the alert function is common for JavaScript developers, but these days there are other options for monitoring a script, including...

Talkback

<cough>Venkman</cough>

via Facebook 10 May, 2006 19:19
Reply

Post your comment

In order to post a comment you need to be registered and logged in.

You can also log in with Facebook. Log in or create your ZDNet UK account below

  • Login

Will not be displayed with your comment

By signing up for this service, you indicate that you agree to our Terms and Conditions and have read and understood our Privacy Policy. Questions about membership? Find the answers in the Community FAQ

Get ZDNet UK's daily newsletter

Enter your email address to sign up

ZDNet UK Live

zdnetukuser

And NOW, folks, for Canonical's next trick... Kubuntu is late. Here's a pencil. Draw your own conclusions. cf.:...

33 seconds ago by zdnetukuser on Linux Minterface
Moley

@kevinmchapman. The discussion here reflects the very significant number of users who really do like the traditional menu system and who wish to...

2 hours ago by Moley on A tale of two distros: Ubuntu and Linux Mint
kevinmchapman

Er, no... It is an efficient means of finding the application/file/setting you need in one place. The icons are a simply a fallback for when you...

4 hours ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
TerryRK

Isn't the provision of a text based search an admission by the developers that the mass of icons approach does not work? I don't need to use a...

5 hours ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
kevinmchapman

"Unity and GNOME 3 both abandon the old text-based cascading menus in favour of a graphical icon-driven system." Point truly missed. Both use a...

5 hours ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
TerryRK

whs001 - Thank you, I'm glad you liked the article. I absolutely agree with you on your first point. I should perhaps have made it clearer that...

5 hours ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
Dennis Nilsson

If we allow corporate interest to dictate the way our government circumvents due process against foreign entities then we should accept the same...

7 hours ago by Dennis Nilsson via Facebook on ACTA stumbles in Germany
GHar123

I totally dislike pirating of works, I fear that artists will be deterred from creating works if they think that they are going to get ripped off....

8 hours ago by GHar123 on ACTA stumbles in Germany
JCB33

How dare film makers, artists or anybody that invests in creativity stop us pirating their works for free. I want to be able to walk into my local...

14 hours ago by JCB33 on ACTA stumbles in Germany
Moley

@GrueMaster. I prefer horses for courses rather than one size fits all. I, and I suspect most other computer users, do not really wish to have...

16 hours ago by Moley on A tale of two distros: Ubuntu and Linux Mint
greycynic

The product that scares me every time I have to use it is the Office 2007 version of Excel. The first bug that I found was applying the median...

16 hours ago by greycynic on Ten flawed products that derail productivity
GrueMaster

Nice review and very informative. One thing I'd like to add (in reply to whs001's 1st question), the main reason to have the same interface from...

18 hours ago by GrueMaster on A tale of two distros: Ubuntu and Linux Mint
Frederick Wrigley

I'be been using Mint 12 since the RC came out, and I am far more happy with the Cinnamon, the Mate, and, yes (with extensions), theGnome 3...

18 hours ago by Frederick Wrigley via Facebook on A tale of two distros: Ubuntu and Linux Mint
bdantas

Excellent article. One small correction, though--although a fresh installation of Linux Mint 12 will, indeed, provide the user with a version of...

19 hours ago by bdantas on A tale of two distros: Ubuntu and Linux Mint
Alan Ralph

In related news, the ISPs club together to get the members of the Home Affairs Select Committee (ya goofed on that part, ZDNet UK) copies of "The...

20 hours ago by Alan Ralph via Facebook on MPs urge ISPs to take down terrorist material
Alan Ralph

In related news, the ISPs club together to get the members of the Home Affairs Select Committee (ya goofed on that part, ZDNet UK) copies of "The...

20 hours ago by Alan Ralph via Facebook on MPs urge ISPs to take down terrorist material
Moley

For Gnome 2 die-hards, it is possible to add icons to the bottom panel (or top top panel, if you prefer) which provide the exact Gnome 2...

20 hours ago by Moley on A tale of two distros: Ubuntu and Linux Mint
ramwellian

Your comments would seem pretty naive and immature. Your 'solution' appears to be, "gee, let's all just give in to the hackers and give them...

21 hours ago by ramwellian on Cloud computing security: no more oxymoron?
BugStalker

"Interesting thought ... If you installed Win7 as a dual boot on a machine that previously only had Linux, and it wrecked your Linux installation,...

21 hours ago by BugStalker on Windows 7 Declares War on GRUB
whs001

This is an excellent summary of Ubuntu and Mint and the interface differences between them. Most such articles take a very partisan position for...

21 hours ago by whs001 on A tale of two distros: Ubuntu and Linux Mint

Latest in Application Development