0

http://jsbin.com/idazeg/edit#javascript,html

Can someone tell me how and why this is working?

$('#pp').click (function () {
    ppp:doSomething('2'); //<=== ppp , how is JS **eating** this ?
});
Andy E
  • 326,646
  • 82
  • 467
  • 441
Royi Namir
  • 138,711
  • 129
  • 435
  • 755

2 Answers2

10

ppp: is a label statement. It's syntactically equivalent to:

ppp:
doSomething('2');

It's mostly useless here, most devs reserve them for allowing greater control over nested loops:

loop1:
for (var i = 0; i < 3; i++) {      //The first for statement is labeled "loop1"
   loop2:
   for (var j = 0; j < 3; j++) {   //The second for statement is labeled "loop2"
      if (i == 1 && j == 1) {
         continue loop1;
      } else {
         console.log("i = " + i + ", j = " + j);
      }
   }
} 
Andy E
  • 326,646
  • 82
  • 467
  • 441
0

My guess is that in the above case the ppp: just works as a label. So there would be no difference if you remove it and only use doSomething('2');

Christian Wattengård
  • 5,373
  • 4
  • 29
  • 42