Guest User

Untitled

a guest
Apr 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. What is scope?
  2.  
  3. Scope determines whether variables can or can't be accessed in different places in your code. Globally scoped variables can be accessed anywhere in your code. When a variable is declared outside of a function it is globally scoped. Global scope can span across different files. Variables defined inside functions are locally scoped, meaning they can only be accessed within that function. This means that variable names can have the same name as long as they are defined in different fuctions. You can define a variable with the same name as a global variable inside of a function and it will be seperate from the global variable.
  4.  
  5. Why are global variables avoided?
  6.  
  7. We avoid global variables because they can cause unintended side effects. This can lead to code that is difficult to debug.
  8.  
  9. Explain JavaScript's strict mode
  10.  
  11. Strict mode makes it easier to write more robust JavaScript code. It throws errors instead of silently accepting bad syntax. It makes it impossible to create global variables.
  12.  
  13. What are side effects, and what is a pure function?
  14.  
  15. A side effect is when a function reaches outside it's local scope and alters a variable. A pure function is a function that doesn't rely on or modify variables outside of it's own scope. It will always return the same result given the same parameters.
Add Comment
Please, Sign In to add comment