Hacker Newsnew | comments | show | ask | jobs | submit login

Actually, while it's almost never used (I certainly haven't seen code using it), blocks cooperate with labels too. The following is perfectly valid:

  var fn = function() {
      nowWeDance: {
          dance();
      }
  };
The block uses the same execution context and scope, of course, so it's not useful.

A block is legal alone too:

  (function() {
      {
          return 1;
      }
  })(); // 1
I suppose for a very long switch statement (god forbid), blocks could be useful:

  switch (x) {
      case 1: {
          // do stuff
          break;
      }
      case 2: {
          // do stuff
          break;
      }
  }
But I wouldn't favor it because it makes the break seem implicit to the reader when it in fact is not.





Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: