The method of judging null, undefined and nan in JS
This article mainly introduces the method of judging null, undefined and nan in JS, the need of friends can refer to the following. Wrote a str.="s"++and then Nan, looking for a while. The information collected is as follows:1. Judge undefined: Copy the Code code as follows:<span style="Font-size:small;">varTMP =undefined;if(typeof(tmp) = ="undefined") {alert ("undefined"); }</span>Description:typeofThere are six possible types of strings that are returned:" Number"、"string"、"Boolean"、"Object"、"function"、"undefined" 2. Determine null: Copy the code code as follows:<span style="Font-size:small;">varTMP =NULL; if(!tmp &&typeof(TMP)! ="undefined"&& tmp!=0) {alert ("NULL"); }</span>3. Determine the nan: Copy the Code code as follows:<span style="Font-size:small;">varTMP =0/0; if(IsNaN (TMP)) {alert ("NaN"); }</span>Note: If you compare NaN to any value (including its own), the result will befalse, so to determine if a value is NaN, you cannot use = = or = = =operator. Tip: the IsNaN () function is often used to detect the results of parsefloat () and parseint () to determine whether they represent a valid number. Of course, you can also use the IsNaN () function to detect arithmetic errors, such as0the case of divisor. 4. Determine undefined and null: Copy code code as follows:<span style="Font-size:small;">varTMP =undefined;if(tmp==undefined) {Alert ("null or undefined"); } </span>Copy the code code as follows:<span style="Font-size:small;">varTMP =undefined;if(tmp==NULL) {alert ("null or undefined"); }</span>Description:NULL==undefined<!--endfragment-->5. Determine undefined, null, and Nan: The copy Code code is as follows:<span style="Font-size:small;">varTMP =NULL; if(!tmp) {Alert ("null or undefined or NaN"); }</span>tip: It is often enough to use this less differentiated.
Judgment string contains, ignoring case:
Change them all to uppercase or lowercase, and then compare them. The character position of the substring within the first occurrence of the IndexOf object with toLowerCase or touppercase
Resources:
Http://www.jb51.net/article/48481.htm
Http://www.cnblogs.com/binaryworms/archive/2010/04/08/1707064.html
Http://www.cnblogs.com/mingforyou/archive/2013/03/04/2942453.html
http://rock541.iteye.com/blog/1707764
Http://www.jb51.net/article/15445.htm
Http://www.ijavascript.cn/jiaocheng/javascript-indexof-244.html
"Front-end" javascript determines undefined, null, NaN, string inclusions, and so on