Skip to content

Instantly share code, notes, and snippets.

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 brianjeremy/033b43dff9abc0cdb2a06c31809a71f8 to your computer and use it in GitHub Desktop.
Save brianjeremy/033b43dff9abc0cdb2a06c31809a71f8 to your computer and use it in GitHub Desktop.
Thinkful JS: Variable Scope
What is scope? Your explanation should include the idea of global vs. block scope.
Scope defines where variables, functions, and objects are accessible throughout a particular piece of code. Items defined in global scope are accessible anywhere whereas items defined in block scope only exist and are accessible within that specific block of code.
Why are global variables avoided?
Global variables are to be avoided because they are easily forgotten about and thus increase your risk of collision and they are less performant than local variables. Additionally they make code readability more challenging which is not ideal for collaboration,.
Explain JavaScript's strict mode
Javascript strict mode evaluates code with addition restrictions which prompts developers to adopt better coding syntax and practices. Additional errors/exceptions are thrown at runtime which would otherwise go undetected which in turn helps reduce bugs or defects that could go unnoticed.
What are side effects, and what is a pure function?
Side effects are when a state change occurs outside of the local scope. A pure function is one where the same input always yields the same output and where there are no side effects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment