Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. 1) What is scope? Your explanation should include the idea of global vs. local scope.
  2. Scope is like the boundraies in which local variables and global variables exist. In the case of local scope, it is a reference
  3. to any variables declared or used within the function declaration brackets {}. Global scope are variables not declared within
  4. the specific scope of a function, so they are accesable to all functions and even code outside fucntions.
  5.  
  6. 2) Why are global variables avoided?
  7. They can cause uninended side effects. For example, indeterminate function. We want functions to be determinate, so they always
  8. behave the same exact way. But once they inteact with code in the global scope, this can cause things to get changes locally
  9. causing erratic behavior.
  10.  
  11. 3) Explain JavaScript's strict mode.
  12. Strict does not allow undeclared variables to get defaulted to being defined in the global scope. In javascript, by default,
  13. 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
  14. regardless of whether that happens in a function or not.
  15.  
  16. 4) What are side effects, and what is a pure function?
  17. As described above side effect can be the result of a function accessing variables in the global scope and using their values
  18. to change run code within the local block, such as variable definitions. In the case if a pure function, it would only use
  19. variables contained within its local scope and be self-contained.
  20.  
  21. 5) Explain variable hoisting in JavaScript.
  22. When the JavaScript interpreter pareses the code, it changes the way it is written behind the scenes. A part of that is
  23. pulling any function and variable declarations above everything else, so that they are readily available once code starts
  24. to get executed. This is done inside of functions at the local variable level, and is also done within the global scope as well.
  25. It is why you can execute a function before it is declared.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement