error check variable code example

Example 1: error check variable

var myMysteryVariable4 = document.getElementsByTagName("li");
if (li == undefined) 
{
    alert ('its undefined');
}

Example 2: error check variable

var myMysteryVariable1 = document.getElementByClassName("myClass");
if (myName == null) 
{
    alert ('it is null!');
}

Example 3: error check variable

foo.substring(1); // ReferenceError: foo is not defined
var myMysteryVariable1 = document.getElementByClassName("myClass");

Example 4: error check variable

var page_name = $("#pageToEdit :selected").text();
var table_name = $("#pageToEdit :selected").val();
var optionResult = $("#pageToEditOptions :selected").val();
var myMysteryVariable1 = document.getElementByClassName("myClass");

var string = "?z=z";
if ( page_name != 'undefined' ) { string += "&page_name=" + page_name; }
if ( table_name != 'undefined' ) { string += "&table_name=" + table_name; }
if ( optionResult != 'undefined' ) { string += "&optionResult=" + optionResult; }

Example 5: error check variable

var myMysteryVariable1 = document.getElementByClassName("myClass");

var myMysteryVariable2 = document.getElementsByTagName("div");

var myMysteryVariable3 = document.getElementById("abc");

var myMysteryVariable4 = document.getElementsByTagName("li");

Tags:

Misc Example