a guest Apr 19th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- What is scope? Your explanation should include the idea of global vs. block scope.
- A: Scope interepts the variables declared that can be accesed at various places in your code. Scope determines where you can access the variables in your code.
- Global scope declares a variable outside of a function. Variables inside the global scope can be accessed and altered
- Local scope declares a variable inside of a function . Local scope variables inside of a function can have the same name and serve a different function.
- Variables declared inside a function without var keyword also become global variables.
- Why are global variables avoided?
- A: The code is easier to interpret when it is broken down into smaller parts. Global variables can be read or modified by any part of the code. Which can can cause bugs when calling a function.
- A: Not using let or const causes issues when creating variables. using strict mode at the top of a file or function will cause an error letting you know that a variable was created without using let or const.
- What are side effects, and what is a pure function?
- A: Side effects is when data is modified in a variable of the same name delared as both global and local. Pure functions are when a functions input is accepted and returns a value without modification.
RAW Paste Data