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.
- Scope in the extent of JavaScript determines what specific parts of the program are accessible.
- Variable scope is the idea that certain variables can or cannot be accessed depending on where and how they’re declared.
- Why are global variables avoided?
- In javascript variable declared inside a function has local scope(accessible only within the block of that function.)
- If a variable inside a function has the same name as a global variable(outside a function), the local variable takes precedence
- and is then altered to the new declared value. In other words, a function can change the value of a global variable.
- If another function comes along that depends on the original value of the global variable, this can create problems
- and break the program.
- Explain JavaScript's strict mode
- As I understand it, a variable without var, let or const is automatically a global variable.
- To avoid this, JavaScript has a strict mode feature so that any variable declared without let or const creates an error.
- It’s like variable proofing.
- What are side effects, and what is a pure function?
- A side effect is when a function goes outside of its local scope and starts changing values in parent scopes.
- If other parts of the program are depending on the original values and the function comes along and changes them,
- this creates indeterminate code. Meaning, if I give the function the same input, sometimes it gives me one thing and
- other times it gives me another thing. It is not reliable 100% of the time. A pure function is determinate code.
- That is, if I give that function the same input it will return the same thing 100% of the time.
Add Comment
Please, Sign In to add comment