javascript is string null or empty code example

Example 1: javascript null or object

What it is  	 		What output shows you 
 				when you write |console.log(typeof(variable);
Undefined:					"undefined"
Null:						"object"
Boolean:					"boolean"
Number:						"number"
String:						"string"
Function object:			"function"
E4X XML object:				"xml"
E4X XMLList object:			"xml"
NodeList					"Nodelist [more data]"
HTMLCollection				"HTMLCollection(1) [more data]"

Example 2: javascript if string empty

// Test whether strValue is empty or is None
if (strValue) {
    //do something
}
// Test wheter strValue is empty, but not None 
if (strValue === "") {
    //do something
}

Example 3: javascript check if undefined or null or empty string

// simple check do the job
if (myString) {
 // comes here either myString is not null,
 // or myString is not undefined,
 // or myString is not '' (empty).
}

Example 4: javascript check if empty

//check if string is undefined 
if (typeof myVar === 'undefined'){
  console.log("I am not defined");
}

//check if string is empty, null, or 0
var emptyString="";
if (emptyString) {
    console.log("im not empty");
}

Tags:

Php Example