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
  • 338,112
  • 86
  • 474
  • 445
Royi Namir
  • 144,742
  • 138
  • 468
  • 792

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
  • 338,112
  • 86
  • 474
  • 445
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,543
  • 5
  • 30
  • 43