Skip to content

Instantly share code, notes, and snippets.

@wolframkriesing
Created October 25, 2019 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolframkriesing/a648b085dc634b47a7c03c8386dbe829 to your computer and use it in GitHub Desktop.
Save wolframkriesing/a648b085dc634b47a7c03c8386dbe829 to your computer and use it in GitHub Desktop.
using braces to limit scopes
const findUser () => {
{
const userOrError = findUserInCache();
if (userOrError instanceof Error) return userOrError;
if (userOrError instanceof User) return userOrError;
}
{
const userOrError = findUserInDb(); // reusing `userOrError` inside the same fn
if (userOrError instanceof Error) return userOrError;
if (userOrError instanceof User) return userOrError;
}
return new NoUser();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment