Yes: any operator?

If I put this line in the JavaScript console (you don't need to declare "foo")

foo : 4;

      

What exactly does this line mean? Does "foo" live in any context? Is: any operator?

+3


source to share


1 answer


This is the label :

From the docs:

The designated statement can be used with the break or continue statements. It is a prefix operator with an identifier that you can refer to.



In other programming languages, such as C labels, they are often used with the goto statement . JavaScript has no goto

. In javaScript, it can be used with operators break

or continue

.

Example from docs using tagged continue

with loops:

var i, j;

loop1:
for (i = 0; i < 3; i++) {      //The first for statement is labeled "loop1"
   loop2:
   for (j = 0; j < 3; j++) {   //The second for statement is labeled "loop2"
      if (i === 1 && j === 1) {
         continue loop1;
      }
      console.log('i = ' + i + ', j = ' + j);
   }
}

// Output is:
//   "i = 0, j = 0"
//   "i = 0, j = 1"
//   "i = 0, j = 2"
//   "i = 1, j = 0"
//   "i = 2, j = 0"
//   "i = 2, j = 1"
//   "i = 2, j = 2"
// Notice how it skips both "i = 1, j = 1" and "i = 1, j = 2"

      

+4


source







All Articles