Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. Prompt:
  2. 1. What is scope? Your explanation should include the idea of global vs. block scope.
  3. 2. Why are global variables avoided?
  4. 3. Explain JavaScript's strict mode
  5. 4. What are side effects, and what is a pure function?
  6.  
  7. Scope has many valuable purposes and is widely used. Scope allows you to set different rules to specify when and how your code
  8. can access a variable. Two types of scope are Block and Global. Block scope is set between specific functions and only effects
  9. code inside that function. Global variables are avoided because it allows your code to be bug prone, and harder for multiple
  10. contributors to work on it. Global variables can cause your code to become indeterminate. Meaning that it can return different
  11. values. These values can sometimes not be intended, and make it difficult to track bugs. Block scopes allow us to define only
  12. within the parameters we set. This is an example of a side effect.
  13.  
  14. Side effects occur when a function goes outside the local scope and into the parent scope, which can
  15. cause the code to become indeterminate as mentioned earlier. A function that is determinate (meaning it's a function that always
  16. returns the same value provided the same inputs) and that also has no side effects is called a pure function. Strict mode acts
  17. as a security when writing code and avoiding pitfalls. Strict mode will trigger an error code when you do not use
  18. let or const when defining a variable. Like "<html lang="en">" at the top of a code, we can use 'use strict' ; at the top of our
  19. Javascript code to enforce it.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement