Skip to content

Files

Latest commit

 

History

History
28 lines (20 loc) · 710 Bytes

no-unreadable-iife.md

File metadata and controls

28 lines (20 loc) · 710 Bytes

Pattern: IIFE with parenthesized arrow function body

Issue: -

Description

Using Immediately Invoked Function Expressions (IIFEs) with parenthesized arrow function bodies creates hard-to-read code. Consider using regular function bodies or separating the logic into named functions.

Examples

Example of incorrect code:

const foo = ((bar) => (bar ? bar.baz : baz))(getBar());
const foo = ((bar, baz) => ({ bar, baz }))(bar, baz);

Example of correct code:

const bar = getBar();
const foo = bar ? bar.baz : baz;

const getBaz = (bar) => (bar ? bar.baz : baz);
const foo = getBaz(getBar());

const foo = ((bar) => {
  return bar ? bar.baz : baz;
})(getBar());