Skip to content

Instantly share code, notes, and snippets.

@jefflombard
Created December 26, 2018 20:06
Show Gist options
  • Save jefflombard/b9734ed1bc0448e1e696bb2353626820 to your computer and use it in GitHub Desktop.
Save jefflombard/b9734ed1bc0448e1e696bb2353626820 to your computer and use it in GitHub Desktop.
// Don't Do this
let input = document.getElementById('input');
// Checks to see if input is valid.
if (input.value != ''){
callFunction();
}
// Do this instead
let input = document.getElementById('input');
let isValidInput = input.value != '';
if (isValidInput){
callFunction();
}
// By being verbose with code, you don't need as many comments.
// Why is this good?
// Because you are less likely to reimplement `isValidInput` if you need it in the future.
// It keeps your code DRY: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment