Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. block scope.
  2. Answer: Scope determines the accessibility (visibility) of variables. In JavaScript there are two types of scope (Local, Global Scopes).
  3. Variables defined inside a function are not accessible (visible) from outside the function. Variables declared within a JavaScript function, become LOCAL to the function.
  4. Local variables have function scope, they can only be accessed from within the function.A variable declared outside a function, becomes GLOBAL.
  5. A global variable has global scope, all scripts and functions on a web page can access it.
  6.  
  7. Why are global variables avoided?
  8. Answer: Global variable are avoided because they can create bugs.It will make the application hard to maintain and read.
  9. Looking for global variables just to know how they were created or manipulated will take some time.
  10.  
  11. Explain JavaScript's strict mode
  12. Answer: It helps with writing a cleaner code, and prevents you from using undeclared variables.
  13. Strict mode is declared by adding "use strict"; to the beginning of a script or a function.
  14. Strict mode makes it easier to write β€œsecure” JavaScript.
  15.  
  16. What are side effects, and what is a pure function?
  17. Answer: A side effect is when a function reaches outside its local scope up into a parent scope and alters a value that lives there.
  18. A function is said to be pure when it is both determinate and has no side effects.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement