Advertisement
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. block scope.
- Variable scope is a set of rules that define which part of the code can alter a pariticular variable.
- It allows us to reuse variable names at different points in our code without enoutering bugs or glitches.
- There are two types of scope called global and block scope. Global scopes are any variables declared outside of a function.
- On the otherhand, block scopes are variable decalred within a fucntion and is only accessible within that function's block of instructions.
- Why are global variables avoided?
- Global variables should be avoided because of uninteded side effects they may cause.
- Global scopes may span across files, and therefore may cause uninteded consequences or changes if two separate files share the same variable.
- Functions may also unintentially affect and change the values of global variables.
- Explain JavaScript's strict mode
- JavaScipt's strict mode prevents global scope and therefore potential bugs within our codes.
- You can put 'use strict' on top of the the JavaScript file or on top of a function.
- When this is used, anytime a variable is delcared without the 'let' or 'const' keywords, an error will trigger.
- The trigger will say 'Uncaught ReferenceError' when it is triggered.
- What are side effects, and what is a pure function?
- A side effect is when a function reaches outside its local scope and it starts to look up into a parent scope and then alters a value that lives there.
- Uninteded side effects and global variables together can result in the codes becoming an indeterminate function.
- These functions (the indeterminate funciton) return one value some times and another value another time.
- Pure function, on the other hand, is determinate and has no side effects.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement