阅读背景:

js判断变量初始化的三种形式及推荐用的形式

来源:互联网 

!--NEWSZW_HZH_BEGIN--

<html xmlns="https://www.w3.org/1999/xhtml"> 
<head> 
  <title></title> 
  <script type="text/javascript"> 
 
    //js断定变量初始化有三种情势  
    var x; 
    if (x == null) {  
      alert("x为null"); 
    } 
 
    if (typeof (x) == "undefined") {  
      alert("x为undefined"); 
    } 
 
    //断定变量初始化推举用这类情势  
    if(!x) { 
      alert("不x"); //if(x){} 意思是:变量已被初始化了(初始化了的意思就表现变量已赋值了),或变量不为空,或变量不为undefined  
    } 
     
  </script> 
</head> 
<body> 
<a href=#
<html xmlns="https://www.w




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: