Skip to content

Instantly share code, notes, and snippets.

@joelcorey
Created February 1, 2019 17:35
Show Gist options
  • Save joelcorey/e8ee7aada02be31aaa2694c3107d4d6d to your computer and use it in GitHub Desktop.
Save joelcorey/e8ee7aada02be31aaa2694c3107d4d6d to your computer and use it in GitHub Desktop.
Scope is the "area" in which a variable lives. Unless dealing with specific use cases, such as a library, variables should be kept out of global scope. A function should have one job (single responsibility). This also falls in line with KISS (Keep It Simple Stupid), makes your code easier to read, and easier to maintain. JavaScript's sctrict mode, "use strict;", forces you to use "let" and "const" when declaring variables. This is best practice, and should be how you code. When a function reaches outside of the scope in which it should exist, it can have unintended side effects. A side effect is bad and can be avoided by not using globals. A pure function is when a functions output is only determined by its input.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment