Guest User

Untitled

a guest
Oct 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. local scope.
  2.  
  3. Why are global variables avoided?
  4.  
  5. Explain JavaScript's strict mode
  6.  
  7. What are side effects, and what is a pure function?
  8.  
  9. "Scope" refers to the visibility of variables, which means if your variable can be accessed by different parts of your code or
  10. just within a function's block. Variables can either have a "global" or "local" scope. Variables which are declared outside of a
  11. functions block are automatically created in the "global scope". As well as variables which are declared without "let" or "const"
  12. keyword. Now "local scope" variables are those which are declared within a function, which means that they can only be accessed
  13. within that function. Global scopes are to be avoided and that is because they can create unintended consequences elsewhere in
  14. your code or when you try to run your function again. For this reason, you should always declare your variables within a function
  15. as well as using the keywords, "let" and "const". To avoid accidentally declaring variables you should take advantage of JavaScript's
  16. "use strict;" mode. Strict mode will alert you at any time a variable is declared without the let or const, an error will be triggered.
  17. So you can avoid any more bugs in your code you should also strive to make your functions "pure". This means that your function is both
  18. determinate and has no effects outside that functions block.
Add Comment
Please, Sign In to add comment