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. local scope.
- Scope refers to how variables behave within a file. If you declare a variable outside of a function, then it is considered a global
- variable. A global variable will be used on any part of the code as long as that same variable isn't used inside of a section of code.
- For example:
- let x = 'optimusPrime'; //global variable
- function(megatron) {
- console.log(x); //since x isn't stated in any way in this function, when megatron is ran, it will display 'optimusPrime'.
- }
- If a variable isn't declared within a function, the computer will look up the scope chain to find if the variable has been declared
- somewhere else.
- Why are global variables avoided?
- Globals are avoided because they can create side effects to your code as well as change variables from the local scope to the parent scope.
- This leads to indeterminate situations.
- Explain JavaScript's strict mode
- Strict mode = 'use strict' and can be put at the top of any file to affect the entire file or put within individual functions to use
- strict mode inside that particular function only. Strict mode means that any variable that is issued without let or const before it
- will trigger an error.
- What are side effects, and what is a pure function?
- Side effects is when a function reaches outside of the local scope to the parent scope and alters a value that lives there. A pure
- function is a function that doesn't have any indeterminate values and doesn't have any side effects.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement