1. Home
  2. Computing & Technology
  3. JavaScript

Common Javascript Errors
Page 3

By , About.com Guide

Missing Semi-colon.

Each Javascript statement should end with a semi-colon. Sometimes you see Javascript code where each statement is on a separate line and the semi-colons have been left off but if you need to rearrange the code for any reason you will soon find that it stops working if you end up with two statements on the same line and have forgotten to add in the semi-colon.

The simplest way to resolve this problem is to reformat your code so that each statement appears on a separate line and make sure that each line ends with a semi-colon. You can always combine lines together gradually after you get the code working.

Capitalization mismatch.

Javascript is case sensitive. This means that myvar and myVar are two separate variables. To avoid creating a problem with referring to the wrong variable due to capitalization errors I suggest that you adopt a standard approach to naming your variables by either capitalizing the first letter of the second and subsequent words in the variable name eg. thisIsMyVariable or by separating the words with underscores eg. this_is_my_variable. This will avoid the possibility of your creating two variables whose names only differ in the capitalization used and will make it more obvious when you are looking for errors that the variable name has been specified with the incorrect capitalization.

Another problem if you do name two variables the same is that not all browsers correctly implement the case sensitivity and will treat variables that differ only in capitalization as being the same variable which can result in code with incorrectly capitalized variable names working in some browsers but not others.

Explore JavaScript
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Problem Solving
  5. Common Javascript Errors 3>

©2009 About.com, a part of The New York Times Company.

All rights reserved.