Home

IIFE over let

Gunar Gessner

Gunar Gessner

Mar 25, 2021

I recommend using IIFEs instead of lets in the situation below.

Benefits:

Before:

let response;
try {
  response = parse(req.buffer);
} catch (e) {
  console.error(e);
}

After:

const response = (() => {
  try {
    return parse(req.buffer);
  } catch (e) {
    console.error(e);
  }
})();


Sign up for the newsletter


Read other stuff