Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. block scope.
  2. Global scope is anything decalred outside of a function. All scripts and functions on the webpage can access it. If you assign a value to a variable that has not been declared it will become a global variable. Most programmers use "strict mode" so global variables cannot be automatically created.
  3. Block scope is any code between the curly brackets {}
  4. Var is function scoped
  5. let and const are block scoped
  6. Function scope is within the function
  7. Block scope is within the curly brackets
  8. Global is any variable not declared within a function
  9.  
  10. Why are Global Variables avoided?
  11. Global variables can be read or modified by any part of the program, making it difficult to remember or reason about every possible use. Another problem with global variables is that since every function has access to these, it becomes increasingly hard to figure out which functions actually read and write these variables.
  12. To understand how the application works, you pretty much have to take into account every function which modifies the global state. As the application grows it will get harder to the point of being virtually impossible (or at least a complete waste of time).
  13.  
  14. Explain JavaScript's strict mode
  15. Strict mode allows programmers to avoid the fear of global variables being automatically created. Strict mode makes sure you are neglecting using global variables and allows for you to have overall cleaner more consise code.
  16.  
  17. What are side effects? What is a pure function?
  18. A function must pass two tests to be considered β€œpure”:
  19.  
  20. 1:Same inputs always return same outputs
  21. 2:No side-effects
  22. Pure functions accept an input and returns a value without modifying any data outside its scope
  23. A side effect is when a procedure changes a variable from outside its scope. So in other words it is the exact opposite of a purefunction.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement