Check for null value in JavaScript

One of my YouTube subscribers recently posted a question related to “bound” data fields.  This reminded me of how data bound fields are often susceptible to being populated with null values if the database is empty.  Here is a little function I wrote to remedy this possibility:

function checkForNull(v_String)
{
 var v_Space = ” “;
 if (v_String == null)
  {
    return v_Space;
  }
else
  {
    return v_String;
  }
}


So, all we are saying here is that if the passed in value (v_String) equals null then return a value of ” ” (one space).  If not, then just return whatever non-null value is there.  This small function is used to “test” the string values of data that is passed from a database to a bound field.

Leave a Reply