Testing is the process that you use to ensure that the script you have written actually does what it is supposed to do.Without testing you have no way to tell whether the script actually works.If it were possible to write scripts perfectly so that they always did exactly what they are supposed to do first time and every time then there'd be no need to test. Exen the experts can't write perfect code all the time though and so we need to test all our scripts in order to locate and fix any errors.
From the viewpoint of testing a script, an error is any circumstance where the script does not do what it is supposed to do. An error may or may not cause the script to actually crash. Simply producing a wrong answer (eg. 1.9999999 instead of 2) or tying up so much of the computer's resources so that it can't calculate the required result in the necessary timeframe are errors.
Another thing to note with respect to errors in your script is that having your script produce an error message to display to the person running the script is not an error in the script. Producing an error message may be exactly what you expect the script to do in response to particular inputs from the user. It is only an error in so far as testing the script is concerned where the results that are produced are not what should be produced in that situation (such as producing an error message with respect to perfectly valid user input).When we talk about errors with respect to testing we are always referring to a situation where the results of the test are different for whatever reason from what the test says that the results should be. Validation of user inputs and the production of error messages where incorrect values are entered is a part of our script itself and we may have tests to ensure that the right error messages are produced when invalid input is entered.
There are several approaches to testing and which approach is the most appropriate one to use is very dependent on just how complicated that your script is.With just short fragments of code that perform simple tasks an ad hoc approach to testing can be used that consists of little more than debugging of the code to ensure that it appears to do what it is supposed to do. More complex scripts require a more formal test plan which to be most effective ought to be written prior to writing the script that is to be tested.
The biggest advantage of a formal test plan is that it documents a series of tests that can be rerun at any time. Since each formal test will specify both the specific inputs that are required to run the test as well as the expected results, rerunning all the tests after any changes are made to the code will confirm whether those changes have accidental side effects on the rest of the script.
Even with ad hoc testing, you can't test without having a prior expectation of what the script is supposed to be doing. If any result is to be considered as valid then any script will do for producing that result and so there'd be no reason for testing. The main difference between ad hoc and more formal testing is that with ad hoc testing you simply 'know' what the result is that you want and if the script produces that result when you test then your test is successful. The biggest disadvantages of ad hoc testing are that there may be situations you overlooked where the script does not produce the desired results and because you have no written test plan there is no way for someone else to easily rerun the testing to verify that the same results as before are produced if changes have been made to the script.
One important thing to note is that any testing of your script is better than no testing and for many simple scripts a small amount of ad hoc testing will be quite sufficient to confirm that the script actually works. Things are entirely different when you have an extremely complex script (eg. a library such as Jquery). With a really complex script that can be used in lots of different ways you not only need a formal test plan that outlines a large number of different tests that will be needed in order to demonstrate that the code actually works but you will also need some form of automated test suite to make rerunning those hundreds of tests easier.