JavaScript global variable, private variable.

Source: Internet
Author: User
<script type= "Text/javascript" >      function  A () {          for (i=0;i<20;i++) {             //  No  var i              Here's I is global variable everyone can access         }     }       function  B () {         for (i=0;i<3;i++) {             //alert (i); I am also a global variable here, return 0 and have only one return               A (); This function returns is i=20             //when i=20  passes  i++  i=21  then does not conform to the i<3 condition, exits directly. So return i=21  this is normal.         } &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;   return  i;     }      Document.writeln (b ());     //variables not write the var definition automatically becomes global, defined as the private variable. There are rules that you programmers don't follow.     //If the above you change to  for (var i  try again.) Blame yourself for not blaming others.

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.