Skip to content

Instantly share code, notes, and snippets.

@jochemstoel
Forked from MPKel/Thinkful-scope-Answers
Created April 1, 2018 16:43
Show Gist options
  • Save jochemstoel/5f96981300a86aec5c120ee4a32609dc to your computer and use it in GitHub Desktop.
Save jochemstoel/5f96981300a86aec5c120ee4a32609dc to your computer and use it in GitHub Desktop.
Scope questions/answers
What is scope?
Put simply, scope is the availability of a variable within a program.
Scope determines which parts of a program have the ability to access and manipulate a variable.
A global variable is available for access/manipulation by all parts and collective files(*sometimes) of a program.
A local variable's access is restricted to the function or block within which it was declared.
Why are global variables avoided?
Global variables are avoided because they create the possibility of unexpected side effects,
namely the unintended manipulation of variables, which causes functions to become indeterminate.
Indeterminate functions lead to frustrating and difficult to track down bugs.
Explain JavaScript's strict mode:
Strict mode causes an error anytime a variable is created without the 'let' or 'const' keywords.
When writing functions, this forces new variables to be created within the local scope of the function, avoiding the
possibility of accidentally manipulating a global variable.
What are side effects, and what is a pure function?
Side effects are results/output other than what is expected/intended. Specifically in this context, they are the creation of indeterminate
functions that will not always create the same output when given a single set of inputs.
A 'pure' function is both determinate and has no side effects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment