a guest Feb 19th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- Questions to answer:
- What is scope? Your explanation should include the idea of global vs. block scope.
- Why are global variables avoided?
- What are side effects, and what is a pure function?
- Scope refers to the extent of which parts of your code has access to specific variables/functions declared within the program. Variables declared outside of a function will have global scope. Variables declared within a function will have block scope. Block scope will only be accessible within that block of code (namely, the function). Outside of the function the variable will cease to exist. Global variables will be accessible and modifiable everywhere in your program. Global variables are largely avoided, because functions may inadvertantly modify a global variable, also known as a side effect.
RAW Paste Data