SHARE
TWEET

Untitled

a guest Feb 19th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Questions to answer:
  2. What is scope? Your explanation should include the idea of global vs. block scope.
  3. Why are global variables avoided?
  4. Explain JavaScript's strict mode
  5. What are side effects, and what is a pure function?
  6.  
  7.   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.
  8.  
  9.   A function is determinate when it produces the same output (given the same input) regardless of when it is run in the program. Global variables tend to make this more challenging. A pure function is a function that is determinate, and has no side effects (except for purely intended side effects). A side effect is when a function affects affects variables outside of its block. An example of an intended side effect would be updating a database (since the database will exist outside of the function). Javascript's strict mode is used to not allow variable declaration outside of let and const. This prevents side effects because utilizing varaiables within a function, the programmer must use let/const to declare new variables first. This removes, ambiguity for JS to identify which variable the program is reffering to.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top