Skip to content

Instantly share code, notes, and snippets.

@joepie91 joepie91/.js

Last active Sep 30, 2016
Embed
What would you like to do?
Braces for conditionals
// The wrong way:
if (something === true)
doAThing();
// Requirements change, now you need to do two things:
if (something === true)
doAThing();
doASecondThing();
/* You now have a bug, and potentially a vulnerability. doASecondThing will ALWAYS run, whether your if
* statement is true or not. It's too easy to overlook this, and *will* go wrong at some point.
* Case in point: https://www.imperialviolet.org/2014/02/22/applebug.html */
// The correct way:
if (something === true) {
doAThing();
}
// Which, if requirements change, becomes:
if (something === true) {
doAThing();
doASecondThing();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.