Skip to content

Commit

Permalink
add note that the void operator doesn't work on arrow function iifes (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkwaiblinger authored Sep 12, 2024
1 parent 8ca92ab commit 167a819
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions files/en-us/web/javascript/reference/operators/void/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ This is a bit longer than wrapping the function expression in parentheses, which
})();
```

Note that this trick only applies to IIFEs defined with the `function` keyword. Attempting to use the `void` operator to avoid parentheses for an arrow function results in a syntax error. Arrow function expressions always require parentheses around them when being called.

```js example-bad
void () => { console.log("iife!"); }(); // SyntaxError: Malformed arrow function parameter list
```

### JavaScript URIs

When a browser follows a [`javascript:` URI](/en-US/docs/Web/URI/Schemes/javascript), it evaluates the code in the URI
Expand Down

0 comments on commit 167a819

Please sign in to comment.