Empty judgment applet

1. Analyzing undefined:

var tmp = undefined; 
if (typeof(tmp) == "undefined"){ console.log("undefined"); } 

Description: typeof returns a string, there are six possible: "number", "string", "boolean", "object", "function", "undefined"

2. The judgment null:

var tmp = null; 
if (!tmp && typeof(tmp)!="undefined" && tmp!=0){ console.log("null"); } 

3. decision NaN:

var tmp = 0/0; 
if (isNaN(tmp) ){ console.log("NaN"); } 

Description: to indicate the illegal NaN, NaN if the result of any value (including itself) are obtained compared to false, so to determine whether a NaN value, or can not use == === operator.

Tip: isNaN () function is commonly used to detect the result parseFloat () and the parseInt () to judge whether or not they represent a legitimate number. Of course, also be used isNaN () function to detect an error count, such as the case with 0 divisor.

And 4. Analyzing undefined null:

var tmp = undefined; 
if (tmp== undefined) 
{ 
   console.log("null or undefined"); } var tmp = undefined; if (tmp== null) { console.log("null or undefined"); } 

Description: null == undefined

5. Analyzing undefined, null and NaN:

var tmp = null; 
if (!tmp) 
{ 
   console.log("null or undefined or NaN"); } 

Tip: Generally not so distinguished on the use of this enough.

6. Analyzing null object

Let the beginning of an object set to null, null by the judge to determine whether

7. determines optionswhether there

if(options){ //存在 }else{ //不存在 }To

Original: https://www.jianshu.com/p/ed52f2609fe6

Guess you like

Origin www.cnblogs.com/it66/p/11353959.html