a guest Sep 20th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- What is scope? Your explanation should include the idea of global vs. block scope.
- A scope is basically defining which part of your code can access certain variables. There are two different kinds of scope:
- global and block scope. Block scope is where the variable is only accessible in your function. Global scope is where the
- variable is accessible everywhere, including other files. Global scope tends to cause unintended side effects, which almost
- guarantee your code to become indeterminate.
- Why are global variables avoided?
- Because they tend to cause unintended side effects, leading your code to almost guarantee to become indeterminate, which is
- something we do not want. We want our code to be pure. In other words, we want our code to not have unintended side effects
- and be determinate.
- when the keyword "let" or "const" is not used to declare a variable an error will occur. Strict mode can be enabled by adding
- the general rule is to place it at the top of the file.
- What are side effects, and what is a pure function?
- Side effect is when a variable goes outside of its local scope, up into its parent scope, and alter the value there.
- Unintended side effects tends to be caused by global scope.
- A pure function is a function that has no side effects and is determinate - it will always return the same value given that
- it is always provided with the same input.
RAW Paste Data