Strings are relatively safe as parameters, but numbers and booleans are not. This is because JavaScript often converts a non-string, such as 5, to the corresponding string “5,” but it only converts to numerical or boolean values if it can.
If a string parameter is specified as the number 5, no error occurs, because the numerical value 5 and the string “5” may be freely converted to one another. If a numerical parameter is specified as the string “five,” an error very definitely occurs, because JavaScript does not know how to convert that string to a number.
Leave a Reply