null is used as "no value" or "no object". In other words, it holds no valid number, string, Boolean, array, or object (array and objects are complex data types we will get back to later). You can erase the contents of a variable (without deleting the variable) by assigning it the null value. Note that the value undefined and null compare as equal using the equality == operator, but not when using the === operator.
In both JavaScript and JScript, null does not compare as equal to 0 using the equality operator. This behavior is different from other languages, such as C and C++.
Removing an Answer in a Single or Grid Question
You can use null to "remove" an answer to a question with a radio button (i.e. single or grid questions). Say you have a page with two single questions, present1 and present2, at the end of the survey. The respondent should answer just one of the questions, where the respondent can choose between two lists with incentives (for example wine or CD):
Figure 1 - Removing an answer to a question with a radio button
You must set the "Not required" property on both questions. It is quite easy to write validation code to give an error message when both questions are answered (as in the figure above), but the respondent cannot de-select the answers since this is not possible with radio-buttons. Then you must remove the answers to the questions in the validation code, i.e. setting them to the null value:
if(f("present1").toBoolean() && f("present2").toBoolean()) //both questions answered
{
//Remove answers on both questions:
f("present1").set(null);
f("present2").set(null);
//Provide error message
RaiseError();
SetErrorMessage(LangIDs.en,"Please select either a bottle of wine or a CD.");
}toBoolean is used to check if there is an answer on a question (go to toBoolean for more information). set is used to set the value of a question (go to get and set for more information).
This validation code will give this result when trying to move to the next page after selecting an answer on both questions:
Figure 2 - Validation code result