Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MoNarchEnterprises/77ec7e04411bb5d73b5e6cabebed716b to your computer and use it in GitHub Desktop.
Save MoNarchEnterprises/77ec7e04411bb5d73b5e6cabebed716b to your computer and use it in GitHub Desktop.
Scope
Questions
What is scope? Your explanation should include the idea of global vs. local scope.
Scope determines what parts of the code have direct access to a variable and can mutate that variable's value. A global variable
can be accessed by all parts of the code and can be changed in any place where it is accessed. A local variable can only be accessed or
changed within the function block that it is defined in.
Why are global variables avoided?
Global variables are able to be changed in any part of the code, so it makes programs indeterminate. If a value of a global variable is
changed then it's difficult to know where that change occurred.
Explain JavaScript's strict mode
Strict mode will throw an error if a variable is used in a function without declaring with a let, var, or const. This helps to eliminate
global variables
What are side effects, and what is a pure function?
Side effects are changes to variables outside of a function. Usually occur when global variables are used. A pure function has no
side effects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment