|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 7
function test () {
alert ("hello")
Even if your script loads without a peep, there is no guarantee that it will run smoothly. Runtime errors are those that occur when the script is actually playing. As with load-time errors, runtime errors are displayed in an alert box. The nature of the error is specified, along with a line number (which isn't always accurate), so you can hunt down the error in the same document.
Where load-time errors are generally caused by mistakes in syntax, runtime errors are most often due to improper use of commands. For instance, you will receive a runtime error if you reference a variable that hasn't been defined. The following results in a runtime error.
Messsage = "This is a test"; // note three s's
document.write(Message); // note two s's
Another type of runtime error occurs when you misapply one of JavaScript's objects. For example, this code fragment results in an error ("document cannot be set by assignment.") because you cannot assign a value directly to the document object.
document="test";
Finally, a logic error is when your script does something different than that suggested by logic. The error isn't due to a misplaced parenthesis or misapplied statement, but rather to a mistake in the way you've constructed the script. For example, a logic error occurs if you fail to anticipate the user entering invalid data. The script may fail because the data it processes is not in the proper format.
You'll find that most of the errors that beset your scripts are caused by the same, and rather simple, mistakes. Make sure you look for the following:
MyVar and MyVal. Avoid one-character differences in variable names, such as Name and Names. And, of course, be sure that the variables you use are spelled properly throughout the script. Remember: JavaScript variables
are case sensitive. MyVar is not the same as myvar.
for statement (following C and Java practice), JavaScript uses the comma as the separator character for arguments.
An important step in repairing a broken script is isolating its various functions and routines, and analyzing it on a piece-by-piece basis. This can be done using a number of low-tech approaches, such as setting watchpoints using alert message boxes, and taking advantage of the for/in statement to peer into JavaScript's objects.