Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- What is scope?
- Scope defines what variables are accessible from different points in code. Variables declared in global scope can be accessed
- from anywhere in the code. Variables declared in block scope can only be accessed within that block of code, for example,
- variables declared inside a function are only accessible inside that function.
- Why are global variables avoided?
- Since global variable are accessible everywhere, values can unintentionally be altered throughout the code. This results in
- bugs that are hard to find and can create multiple problems across a program that are difficult to fix.
- Explain JavaScript's strict mode.
- Invoking strict mode at the top of a file or function will trigger an error any time a variable is declared without let or
- const. It is possible to declar a variable without let or const, but this exposes the value to mutation. Without strict mode,
- no errors are thrown, and a programmer can possibly continue writing without being aware of the problems being caused. Strict
- mode will throw errors whenever a variable is declared without const or let, thus preventing mutations.
- What are side effects, and what is a pure function?
- A side effect occurs when a function looks outside its local scope and alters a value there. A pure function is one that
- is both determinate and has no side effects. A determinate function will always return the same value as long as it is given
- the same inputs. A pure function will also only check its local scope for a variable value.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement