Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. block scope. Scope is the concept that your code must follow a set of rules in a specific order for your code to access variables. There are two different types of scope. Global scope is the idea that your variable is available anywhere in your code and can be altered easily. Block Scope makes your variable only available within the function it is being defined in.
  2. Why are global variables avoided? Global variables are avoided because the variable is declared outside of a function and is available everywhere in your Javascript code. This tends to make unintended side effects that will cause your function to look outside of its local scope for a declared variable. Global Variable can also make your code Indeterminate and that makes your code unreliable.
  3. Explain JavaScript's strict mode- Strict mode is a way to prevent a variable from being declared without using let or const. Strict mode will create an error in the console if you have a variable thisCode=thatCode. Strict mode can be used on the top of a script file or just for a certain function. This makes strict mode incredibly valuable.
  4. What are side effects, and what is a pure function? Side effects occur when a function reaches outside of its local scope into a parent scope in search for a variable and in turn alters a value that lives in the parent scope. At times, side effects are meant to occur in a function. Mainly in the event that the function is saving new records for a database. A pure function is a function that is determinate, always the same value if it is provided with the same inputs, and has no side effects. Keep in mind that there is an exception to the side effect rule. That is when the function is meant to have a side effect.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement