Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. Q. What is scope? Your explanation should include the idea of global vs. local scope.
  2. A. Scope is about the visibility of variables in a codebase. We differentiate between global vs local scope. A globally declared variable is accessible throughout the codebase while a locally declared variable is only accessible within a function.
  3.  
  4. Q. Why are global variables avoided?
  5. A. Global variables are to be avoided as much as possible due to the fact that its value can be altered at any point within the codebase causing unwanted side-effects which are difficult to remediate.
  6.  
  7. Q. Explain JavaScript's strict mode.
  8. A. JavaScript’s strict mode assures that it is impossible to declare a without the keyword var. This prevents a locally declared variable to be interpreted as a global variable or mutate an existing global variable.
  9.  
  10. Q. What are side effects, and what is a pure function?
  11. A. A side effect is when a function alters the value of a global variable unintentionally. A pure function is a function which always produces the same result given the same inputs plus never produce any unintentional side-effects.
  12.  
  13. Q. Explain variable hoisting in JavaScript.
  14. A. Variable hoisting in JavaScript is the interpretation of the code by the parser in which it will do an initial pass to first determine all the variable declarations and moves it to the top of the scope. This is the reason why a global or local variable can be declared after its usage in your code without causing a syntax error.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement