JJS the situation of producing undefined

Source: Internet
Author: User

1<script type= "Text/javascript" >2 varOutobj = { 3Type: "Java"4 }5 functioninnerm () {6  varp;7Alert (p);//undefined8Alert ("K:" +k);//error--innerobj Not defined9alert (outobj.jack);//undefinedTenalert (innerobj.jack);//error--innerobj Not defined One } A   - innerm (); -   the</script>
 <script type= "Text/javascript" > alert ( typeof  (false ) = = = ' Boolean '); // true  alert (typeof  (0) = = = ' number '); // true  alert (typeof  ("") = = = = ' String '); // true  alert (typeof  (null ) = = = ' object '); // true  alert (typeof  undefined = = = " Undefined '); // true  </script> 
1  2<script type= "Text/javascript" >3Alertfalse= = undefined);//false4Alertfalse==NULL);//false5Alertfalse= = 0);//true6Alertfalse== "");//true7AlertNULL= = undefined);//true8</script>
<script type= "Text/javascript" >    alert (false. toString ());    // "false"    Alert ("". CharAt (0));        //  ""    Alert ((0). Toexponential (Ten));  // 0.0000000e+0    Alert (undefined.tostring ());    // throw exception "Undefined has no properties"    Alert (null. toString ());             // "NULL has no properties"
1<script type= "Text/javascript" >2Alert (String (false));//"false"3Alert (String (""));// ""4Alert (String (0));//0.0000000e+05Alert (String (undefined));//"undefined"6Alert (String (NULL));//"NULL"7  8Alert (decodeURI (undefined));//"undefined"9Alert (decodeURI (NULL));//"NULL"Ten</script> One   A  
1<script type= "Text/javascript" >2 //false values and Null values as if conditions branch3 //false values and null values have a common denominator, that is, when the conditional branch as if, are treated as false; Apply "!" Is true after the operation. 4 //This is because these objects are considered to be invalid values or null values in their respective types. So those objects in the If branch are treated as false. The following example code:5     varAR = [Undefined,false, 0, "",NULL];6      for(vari = 0,len = Ar.length; i < Len; i++){7         if(Ar[i]) {8Alert ("You should not see this dialog box!"));9         }Ten     } One</script>
<script type= "Text/javascript" >//undefined and Null objects are nothing more than two special objects, undefined represents an invalid object, and null represents an empty object. //if the variable is explicitly or implicitly (assigned by the JavaScript engine), it is given the undefined,//That means that the variable is not defined, and if it is given a null value, it is initialized to a null value. //in JavaScript, a variable is defined by a var declaration, = an assignment (the object to which the variable is initialized). //of course, if you declare a global variable (as the Window property), you can not use the var keyword. Variables can be defined at the same time as the declaration. //If a variable is declared but not initialized, the JavaScript engine automatically points this variable to the undefined object. //It is important to note that when we refer to WINDOW.ABCD above, we pop the undefined, and when we refer to the ABCD variable directly, we throw an exception. //This is because the JavaScript engine tries to find variables from the nearest scope, for variables that do not explicitly specify the chain of objects .//If the lookup fails, it is returned to the parent chain of action to find. If all lookups fail, an exception with "variable undefined" is thrown.      varUndefinedvariable,nullvariable =NULL; alert (undefinedvariable); //"undefined"alert (window.undefinedvariable);//"undefined"alert (WINDOW.ABCD);//"undefined"alert (nullvariable);//"NULL"alert (ABCD);//Throw exception "ABCD is not defined"</script>
1 <script type= "Text/javascript" >2// These two values are also different when doing a numeric operation.  3     alert (1+undefined);    // "NaN" 4     Alert (1+null);             // "1" 5 </script>6  
<script type= "Text/javascript" >alert ("!undefined ..." + (!  undefined)); Alert ("Undefined==false ..." + (undefined==false)); </script>

JJs The undefined occurs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.