Created
December 26, 2018 20:06
-
-
Save jefflombard/b9734ed1bc0448e1e696bb2353626820 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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