Skip to content

Instantly share code, notes, and snippets.

@lxe
Last active January 2, 2016 00:09
Show Gist options
  • Select an option

  • Save lxe/8221936 to your computer and use it in GitHub Desktop.

Select an option

Save lxe/8221936 to your computer and use it in GitHub Desktop.

JavaScript Tips

General advice on what to do and not to do.

1. return early to avoid unnecessary nesting.

Wrong:

function foo (err) {
  if (!err) {
    doStuff();
  } else {
    processErr(err);
  }
}

Right:

function foo (err) {
  // Exit on error
  if (err) return processErr(err);
  
  doStuff();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment