If you discover a bad parameter, you have two choices


If you discover a bad parameter, you have two choices. You can simply abandon all processing, or you can change the bad parameter to some safe default.
It is often preferable to do the latter, and place an error message in a variable that calling routines can check.

One of the nice things about Javascript the language


One of the nice things about Javascript the language is that it is relatively untyped when compared with strongly typed languages like Ada or Pascal.
In JavaScript the same function can return a boolean or a string or a number with impunity.

JavaScript is based on an action-oriented model of the World Wide Web


JavaScript is based on an action-oriented model of the World Wide Web. Elements of a Web page, such as a button or checkbox, may trigger actions or events. When one of these events occurs, a corresponding piece of JavaScript code, usually a JavaScript function, is executed.
That function, in turn, is composed of various statements which perform calculations, examine or modify the contents of the Web page, or perform other tasks in order to respond in some way to that event.