0

How this works?

void function() {}()

I saw an explanation that void transforms the iife from declaration to expression, and every expression must be evaluated, is this right?

Thanks.

2 Answers2

0

When using an immediately-invoked function expression, void can be used to force the function keyword to be treated as an expression instead of a declaration. Check this link at MDN

Hector Barbossa
  • 5,506
  • 13
  • 48
  • 70
  • Is `var x = void function() { return 1; } ()` valid and if yes, does it assign 1 or undefined? – le_m Jun 10 '16 at 02:59
0

Quoting from MDN:

When using an immediately-invoked function expression, void can be used to force the function keyword to be treated as an expression instead of a declaration.

Readup: void operator - Javascript | MDN

Rahul Desai
  • 15,242
  • 19
  • 83
  • 138