JavaScript Basics-var

Source: Internet
Author: User

Variables that use Var will be declared at the beginning of JS, so the VAR variable declaration order does not affect

1 inch // false 2 inch // true 3 aa=5; 4 var bb=2;

Variables use VAR (explicit declaration) as local variables, variables do not use VAR (implicit declaration) as global variables,

1 function Test () {2     a = "n"; 3     var b = "EAA"; 4 }5Test (); 6 //  A 7 // b is not defined

Implicit declaration creates a property of a global object that can be deleted,

1 var a = 5; 2 b=4; 3 Delete A; 4 Delete b; 5 // 5 6 // b is not defined

var a=1; The local variable A is declared and assigned a value of 1;

b=2; First look for a variable B declaration, there is the use of the variable, there is no declaration of a global variable

1 varNUM1 = 1;2num2 = 2;3Console.log ("+num1+", "+num2");// the4+function(){5NUM1 = 11;6     varnum2 = 22;7Console.log ("2--" +num1+ "," +num2);//11,228(function(){9Console.log ("3--" +num1+ "," +num2);//undefined,22Ten       varNUM1 = 111; Onenum2 = 222; Anum3 = 333; -Console.log ("4--" +num1+ "," +num2+ "," +num3 ");//111,222,333 -     }()) theConsole.log ("5--" +num1+ "," +num2+ "," +num3 ");//11,222,333 - }(); -Console.log ("6--" +num1+ "," +num2+ "," +num3 ");//11,2,333

JavaScript base-var

Related Article

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.