JavaScript itself does not determine whether a variable is a null function, because the variable may be string,object,number,boolean and other types, different types, and the judging method is different. So in the article wrote a function, to determine whether the JS variable null value, if it is undefined, null, ", nan,false,0,[],{}, blank string, all return True, otherwise return false
Method:
function IsEmpty (v) {Switch(typeofv) { Case' Undefined ': return true; Case' String ': if(V.replace (/(^[\t\n\r]*) | ( [\t\n\r]*$)/g, '). Length = = 0)return true; Break; Case' Boolean ': if(!V)return true; Break; Case' Number ': if(0 = = = V | | IsNaN (v))return true; Break; Case' Object ': if(NULL= = = V | | V.length = = 0)return true; for(varIinchv) {return false; } return true; } return false;}
Test:
IsEmpty ()//trueIsEmpty ([])//trueIsEmpty ({})//trueIsEmpty (0)//trueIsEmpty (Number ("abc"))//trueIsEmpty ("")//trueIsEmpty ("")//trueIsEmpty (false)//trueIsEmpty (NULL)//trueIsEmpty (undefined)//true
Reprint: http://www.bitscn.com/school/Javascript/201503/463294.html
JavaScript determines if a variable is not a null value