Advertisement
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.
- Explain JavaScript's strict mode
- JavaScript's strict mode allow us to avoid pitfalls like the unintended side effects. When strict mode is enabled, everytime
- when the keyword "let" or "const" is not used to declare a variable an error will occur. Strict mode can be enabled by adding
- 'use strict' at the top of the JavaScript file or function if you only want to use it for the body of the function. However,
- 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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement