Properties of Uninitialized Session Variables in ASP Classic

From time to time I have to remind myself of the following inscrutable facts, so here they are for posterity:

Given an uninitialized Session variable:

IsEmpty(Session("asdfasdf")) = True
IsNull(Session("asdfasdf")) = False
IsNumeric(Session("asdfasdf")) = True
Session("asdfasdf") = "" in an "if" statement returns True

This indicates that a completely uninitialized value appears to be both an empty string and has a numeric value (presumably zero). This is nonsense, especially given the next example.

Given a Session variable initialized to the empty string “”:

IsEmpty(Session("emptystring")) = False
IsNull(Session("emptystring")) = False
IsNumeric(Session("emptystring")) = False
Session("emptystring") = "" in an "if" statement returns True

In this case, we see that an empty string is not numeric. So to verify that a Session variable does not contain a numeric value, you need to also verify it contains a value at all, since empty Session variables appear to not be empty (i.e. they contain a numeric value of 0).

Leave a Reply

Your email address will not be published. Required fields are marked *