Skip to content

Instantly share code, notes, and snippets.

@joncancode
Created May 22, 2017 19:38
Show Gist options
  • Save joncancode/82062009dc96795e716f11aff4c67376 to your computer and use it in GitHub Desktop.
Save joncancode/82062009dc96795e716f11aff4c67376 to your computer and use it in GitHub Desktop.
Scope assignment in my own words
What is scope? Your explanation should include the idea of global vs. local scope.
The scope is what you are able to access within a group of code. Global scope refers to variables that are accessible everywhere, while the local scope is more specific. For example, if a variable is defined within a function, it is local to that function and no where outside of it. However, if a variable is defined outside of this function, it is global and you are able to access it in multiple functions.
Why are global variables avoided?
Global variables make unintended side effects in a program more likely, meaning it will be harder to track down bugs in your code. There is just one global scope as opposed to the many local scopes that can be created (and bugs that can avoided from these multiple scopes).
Explain JavaScript's strict mode
Strict mode is a special feature of Javascript that gives an error message every time a variable is declared without the var keyword.
What are side effects, and what is a pure function?
A side effect is when a function reaches outside its local scope, up into a parent scope and alters a value that lives there. Functions with side effects do something other than returning a value. A pure function is a function that does not have any side effects.
Explain variable hoisting in JavaScript.
Hoisting takes all declarations of a variable inside of a particular scope and moves them to the top of the scope before it starts executing them. One thing to remember is that declarations are hoisted, but initializations are not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment