a guest Jul 12th, 2018 60 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. local scope.
- Global scope is when a variable you define is outside of a function and is available to access anywhere in your code.
- While block scope is a variable defined inside of a function and disapears afterwards.
- Why are global variables avoided?
- We avoid globals so that a variable inside of block scope does not reach into its parent scope and alter another variable
- (aka side effects).
- Once strict mode is enabled (by placing 'use strict' at the top of the file (or inside of a function if that situation was
- necessary) makes sure that variables are not defined with out let or const. (aka something = 'something else'). If we try
- to define variables while in strict mode it will raise an uncaught reference error.
- What are side effects, and what is a pure function?
- A side effect is when a funtcion reaches outside of its local scope into its parent scope and alters a value there.
- A pure function is one that does not have any side effects and that is also determinate (having the same value given the same inputs).
RAW Paste Data