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 is the concept of where values are stored and what parts of your code can access them.
- If a value is stored in the global scope, this means that they can be accessed and
- manipulated anywhere in your code and even in other files. Values stored in local or
- block scope only exist inside of the function they are placed in. They can be manipulated
- within that function, but do not affect the scope(s) outside of them. A locally declared
- variable can have the same name as a parent-scope variable, but it will not affect the outside
- variable.
- Why are global variables avoided?
- Using global variables tends to cause code to get buggy. The function reaches outside of its local
- scope and starts to change the world around it. This is undesired because it causes functions to be
- indeterminate. This means a function can run with the same input many times and get a different
- result each time. This is to be avoided unless you're meant to update the parent value.
- Explain JavaScript's strict mode
- By putting 'use strict'; at the top of your JavaScript file, you force it to error whenever you
- try to declare a value without using the declaration keywords 'let' or 'const.' You can also
- use strict mode locally by placing it on top of your function block rather than at the top
- of your JavaScript file. Unless you have a reason not to, you should always use local scope, and
- 'use strict'; at the top of your file.
- What are side effects, and what is a pure function?
- Side effects are what happens when a function reaches outside of its local scope and changes values
- stored in a parent scope. A pure function is one which does not do this, and also returns the same value
- every time it is fed the same input. Determinite and side-effect free!
Add Comment
Please, Sign In to add comment