Skip to content

Instantly share code, notes, and snippets.

@brian-mcallister-lab49
Created July 30, 2020 23:19
Show Gist options
  • Save brian-mcallister-lab49/a656c16110500578ccabb94981d6a055 to your computer and use it in GitHub Desktop.
Save brian-mcallister-lab49/a656c16110500578ccabb94981d6a055 to your computer and use it in GitHub Desktop.
TIL-Lab49/Combine destructuring and ternary statements for quickly defining multiple variables.

Using a very simple technique using syntax that is already familiar to most JavaScript/TypeScript engineers, you can quickly define multiple variables by combining destructuring and ternary statements.

const { success, result } = isSuccessCondition
  ? { success: true, result: 'success!' }
  : { success: false, result: 'you did something silly!' };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment