Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scope is the idea of where a function gathers or views the variables and values it’s looking for.
- It will start in the function itself and if it cannot find what it’s looking for it will bubble up into the parent.
- This will happen until it reaches the global level or in other words a variables that are accessible to all
- functions and sometimes other files. If the variable or value it’s found even there it will throw an error.
- These types of global variables should be avoided since the functions may cause side effects by un-intentionally
- altering these global variables and changing the results of other functions. When a function that takes a simple
- input begins showing random results its considered a in-determinate function and is likely caused by global variables.
- When a function is free from global variables and returns consistent results it is considered to be a pure function.
- This is what we should strive to write. To help us write this type of consistent code we can use ‘strict’ mode.
- When in this mode is a variable is created without deceleration of let or const , it will throw an error to inform us.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement