Skip to content

Instantly share code, notes, and snippets.

@crystalattice
Created December 29, 2017 21:42
Show Gist options
  • Save crystalattice/195ef95efbd984d38c82a5e9020cb27e to your computer and use it in GitHub Desktop.
Save crystalattice/195ef95efbd984d38c82a5e9020cb27e to your computer and use it in GitHub Desktop.
What is scope? Your explanation should include the idea of global vs. local scope.
Scope is the namespace of a data element. Global scope encompasses the entire code project; global values can be called anywhere within the project. Local scope is contained with a particular function; other functions cannot access those values. It also means that functions within functions cannot be accessed outside the containing function.
Why are global variables avoided?
Global variables can overstep their bounds and cause unintended side effects if they are manipulated in a way that wasn't planned for. For example, if a developer has a global variable and a local variable with the same name, she may forget that fact and call the global variable instead of the local variable, changing the global value and ultimately changing the result of the program.
Explain JavaScript's strict mode
Enforces certain "best practices" for coding, such as throwing an error if a variable is declared without the "var" tag.
What are side effects, and what is a pure function?
Side effects are alternative actions that occur when a function is processing data, such as changing variables in addition to returning a value. A pure function only returns a value and does not have any side effects. Also, the operation of the function is the same every time, i.e. the returned value is guaranteed if the same input is provided.
Explain variable hoisting in JavaScript.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment