Skip to content

Instantly share code, notes, and snippets.

@Richardek
Created September 19, 2018 17:35
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 Richardek/56ffe9ebc96fc8c87c528ebf30b8dce2 to your computer and use it in GitHub Desktop.
Save Richardek/56ffe9ebc96fc8c87c528ebf30b8dce2 to your computer and use it in GitHub Desktop.
Global Variables Challenge
Question 1.
A variable scope determines when variables can be assessed at different parts of the code. A variable in the global scope can be accessed anywhere in the code. On the other hand a variable in a block scope can only be accessed in the function it was defined in.
Question 2.
A global variable can lead to unexpected outcomes due to different parts of the code trying to use the same variable name. For example if a global variable was named xyz, but then a function creates another variable named xyz without using let, or const it can lead to many hard to fix bugs.
Question 3.
Strict mode prevent people from defining variables without using let or const. This stops people from creating global variables within their functions.
Question 4.
Side effects are functions reach outside its local scope to alter things in a parent scope. This is due to using global variables. A function is pure when it has no side effects and is determinate, which means the same input will always give the same output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment