From 167a81945e7292ea5e02251538b09a4467237582 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger Date: Thu, 12 Sep 2024 09:46:39 -0600 Subject: [PATCH] add note that the void operator doesn't work on arrow function iifes (#35857) --- .../en-us/web/javascript/reference/operators/void/index.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/files/en-us/web/javascript/reference/operators/void/index.md b/files/en-us/web/javascript/reference/operators/void/index.md index f4aca5c92ec66d7..ce591b320dfe428 100644 --- a/files/en-us/web/javascript/reference/operators/void/index.md +++ b/files/en-us/web/javascript/reference/operators/void/index.md @@ -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