Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1) What is scope? Your explanation should include the idea of global vs. local scope.
- Scope is like the boundraies in which local variables and global variables exist. In the case of local scope, it is a reference
- to any variables declared or used within the function declaration brackets {}. Global scope are variables not declared within
- the specific scope of a function, so they are accesable to all functions and even code outside fucntions.
- 2) Why are global variables avoided?
- They can cause uninended side effects. For example, indeterminate function. We want functions to be determinate, so they always
- behave the same exact way. But once they inteact with code in the global scope, this can cause things to get changes locally
- causing erratic behavior.
- 3) Explain JavaScript's strict mode.
- Strict does not allow undeclared variables to get defaulted to being defined in the global scope. In javascript, by default,
- if you give a variable a value but don't use the "var" keyword, JS will do it for you, but at the global scope level. This is
- regardless of whether that happens in a function or not.
- 4) What are side effects, and what is a pure function?
- As described above side effect can be the result of a function accessing variables in the global scope and using their values
- to change run code within the local block, such as variable definitions. In the case if a pure function, it would only use
- variables contained within its local scope and be self-contained.
- 5) Explain variable hoisting in JavaScript.
- When the JavaScript interpreter pareses the code, it changes the way it is written behind the scenes. A part of that is
- pulling any function and variable declarations above everything else, so that they are readily available once code starts
- to get executed. This is done inside of functions at the local variable level, and is also done within the global scope as well.
- It is why you can execute a function before it is declared.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement