IIAFEs?

Brandon Benvie bbenvie at mozilla.com
Sat Jun 1 16:22:21 PDT 2013


On 6/1/2013 3:44 PM, Jorge wrote:
> But they're not fully interchangeable, for example I can exit a 
> function at any point with a return, but can I exit a block at any 
> point with a break or something? 

     block: {
       if (true) {
         break block;
       }
     }

> Also a function returns a value, does a block evaluate to something? 
> In any case, I would really like to know which parenthesis or curly 
> braces can I leave out in an immediately invocated arrow function 
> expression, for example this: var x= (=>{ //... })(); Is it correct 
> ES6? Is there anything else that I could rmv in that IIAFE? Thank you! 

You can only get the return value of a block using eval. However you can 
accomplish the same task by assigning to some outside variable.

     let x;
     block: {
       x = 20;
       // do some stuff
       if (condition) {
         break block;
       }
       x = 30;
     }


Some fun stuff you can do with eval:

     console.log(eval("block: { 'a'; if (Math.random() > .5) break 
block; 'b' }"))


More information about the es-discuss mailing list