Skip to content

Instantly share code, notes, and snippets.

@iandesj
Created July 16, 2019 14:40
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 iandesj/e0bdc41dcd242fe11e594113f39ca7c8 to your computer and use it in GitHub Desktop.
Save iandesj/e0bdc41dcd242fe11e594113f39ca7c8 to your computer and use it in GitHub Desktop.
Named Boolean Expressions
// before named boolean expressions
// check if the user is active and if the user has
// dependents
if (user.status === 'active' &&
user.dependents.length > 1) {
// perform something important
}
// before
if (!user.authenticated) {
// take special action
}
// after named boolean expressions
const userIsActiveWithDependents = user.status === 'active' &&
user.dependents.length > 1;
if (userIsActiveWithDependents) {
// perform something important
}
// after
const userIsUnauthenticated = user.authenticated == false;
if (userIsUnauthenticated) {
// take special action
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment