Debugging JavaScript programs
Case sensitive
Let's start with the most common problem in JavaScript.
JavaScript is case sensitive.
This is by far the most common problem you'll meet in the early days of programming.
Try it:
Open NotePad++ and change the line of JavaScript to read:
Alert('Hello world!');
If you run this altered page (Ctrl+Shift+Alt+X from NotePad++) then the page will still
open but you will not see the alert box or any error messages. You will just see the text
in the body of the page.
Debugging
If you select Error Console from the Tools menu in FireFox you will see a message
saying "Alert is not defined" followed by a line number.
This should be the line number of the incorrect Alert command.
Go back to the browser and press F5 a couple of times to refresh the page then look at
the Error Console again. You should see that you've got the same error displayed several
times. Let's fix it.
Open the page in NotePad++, go to the line number that's mentioned and change the Alert
back to alert. Save the file and open it again in FireFox.
Open the Error Console in FireFox again and click on the "Clear" button to remove all the
error messages. Press F5 to refresh the page and check that the Error Console remains
empty.
|