Guest User

Untitled

a guest
Jul 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. Scope is essentially a set of rules for code to determine the value of variables used within it. The code follows these 'rules' while searching for the variable values across the entirety of the code. These rules state that JavaScript will search for variable definitions first within the current function and then it will work its' way outward until it reaches the entire or global scope of the code. This is why it is preferable to create local scope and local variables by defining them within the function they are to be used in.
  2. Global variables can be used all across the code and can easily interfere with functions and other variables, which is why it is best to avoid them. These interferences can cause unintended side effects, for example, the value of a variable outside of the intended function could be altered and this could have a spiraling effect throughout the code. The goal is to create pure functions that do not produce any unintended side effects and always provide the correct results. JavaScript features a helpful 'strict mode' that lets the coder know when they have created variables that could lead to global variables ro unintended side effects by not using the let or const methods.
Add Comment
Please, Sign In to add comment