JavaScript not the same grammar

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

JavaScript in addition to object-oriented part, basic grammar and language like C, but there are also special some of their own, are summarized as follows:

(1)Behind the break and continue to label

Grammar:
break labelname;
continue labelname;
 

Without label, the role of continue in the recent cycle, with label can be applied to the outer loop, which is the C language which cannot do.

For example:

Outer:

for (var i = 1; i <= 10; i++) {

    document.write ("<br />");

    document.write ("i: " + i);

    document.write (" j: ");

      1.     Inner:
  1.     for (var j = 21; j <= 30; j++) {
  2.         if (j == 24) {
  3.             continue Outer;
  4.         }

        document.write (j + " ");

    }

}

 

Output:

i: 1 j: 21 22 23

i: 2 j: 21 22 23

i: 3 j: 21 22 23

i: 4 j: 21 22 23

i: 5 j: 21 22 23

i: 6 j: 21 22 23

i: 7 j: 21 22 23

i: 8 j: 21 22 23

i: 9 j: 21 22 23

i: 10 j: 21 22 23

Take after the label, can change the break statement, and in addition to cycle and switch, also can be used in a statement block.

Loop:

var num = 0;

outPoint:

for (var i = 0 ; i <10 ; i++){

     for (var j = 0 ; j <10 ; j++){

          if( i == 5 && j == 5 ){

                break outPoint;

          }

     num++;

     }

}

alert(num); // Cycle in I was 5, J was 5 when out of circulation, return to the outPoint layer to continue, the output of 55

 

A block of code examples:

cars=["BMW","Volvo","Saab","Ford"];
list:
{
document.write(cars[0] + "<br>");
document.write(cars[1] + "<br>");
document.write(cars[2] + "<br>");
break list;
document.write(cars[3] + "<br>");
document.write(cars[4] + "<br>");
document.write(cars[5] + "<br>");
}
 
Output:

BMW

Volvo

Saab

 

(2)To not declared JavaScript variable to assign values to make it automatically as global variables

If you assign values to variables declared not, this variable will be automatically as a global variable declarations.

This statement:

carname="Volvo";

To declare a global variable carname, even if it is executed within the function.

 

(3)Congruent operator

===

For example:

var x = 5;

X===5 true; x===" 5" false

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Alvis at November 13, 2013 - 8:55 AM