Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Scope is essentially the "reach" of which a particular variable can be accessed by a segment of code. For example, global scope indicates that a variable can be accessed anywhere in the code. Block scope on the other hand indicates that a variable only applies within a function of blocked code.
  2.  
  3. Global variables are avoided because they are interwoven with the entire functionality of the code. This in turn makes it difficult to isolate bugs with collaborators and may cause inadvertent side effects. Side effects occur when a function operates outside of its block and alters a value in its parent code. Limiting the use of global variables makes it easier to achieve code that is a pure function, which is code that produces the same values from the same inputs and contains no side effects. Additionally, the use of "strict mode" in Javascript makes side effects even less likely as it requires the use of variable declarations within functions to avoid any changes to global variables.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement